mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-13 03:47:40 +02:00
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
/*
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE
|
|
* Version 3, 19 November 2007
|
|
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
* of this license document, but changing it is not allowed.
|
|
*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls;
|
|
|
|
namespace UVtools.WPF.Controls
|
|
{
|
|
public class WindowEx : Window, INotifyPropertyChanged
|
|
{
|
|
#region BindableBase
|
|
/// <summary>
|
|
/// Multicast event for property change notifications.
|
|
/// </summary>
|
|
private PropertyChangedEventHandler _propertyChanged;
|
|
private List<string> events = new List<string>();
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged
|
|
{
|
|
add { _propertyChanged += value; events.Add("added"); }
|
|
remove { _propertyChanged -= value; events.Add("removed"); }
|
|
}
|
|
|
|
protected bool RaiseAndSetIfChanged<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
|
|
{
|
|
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
|
field = value;
|
|
RaisePropertyChanged(propertyName);
|
|
return true;
|
|
}
|
|
|
|
|
|
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notifies listeners that a property value has changed.
|
|
/// </summary>
|
|
/// <param name="propertyName">
|
|
/// Name of the property used to notify listeners. This
|
|
/// value is optional and can be provided automatically when invoked from compilers
|
|
/// that support <see cref="CallerMemberNameAttribute" />.
|
|
/// </param>
|
|
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
|
{
|
|
var e = new PropertyChangedEventArgs(propertyName);
|
|
OnPropertyChanged(e);
|
|
_propertyChanged?.Invoke(this, e);
|
|
}
|
|
#endregion
|
|
|
|
public DialogResults DialogResult { get; set; } = DialogResults.Unknown;
|
|
public enum DialogResults
|
|
{
|
|
Unknown,
|
|
OK,
|
|
Cancel
|
|
}
|
|
|
|
public void CloseWithResult()
|
|
{
|
|
Close(DialogResult);
|
|
}
|
|
|
|
public virtual void ResetDataContext()
|
|
{
|
|
var old = DataContext;
|
|
DataContext = null;
|
|
DataContext = old;
|
|
}
|
|
}
|
|
}
|