1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* 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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Styling;
namespace UVtools.WPF.Controls
{
public class WindowEx : Window, INotifyPropertyChanged, IStyleable
{
#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
Type IStyleable.StyleKey => typeof(Window);
public DialogResults DialogResult { get; set; } = DialogResults.Unknown;
public enum DialogResults
{
Unknown,
OK,
Cancel
}
public WindowEx()
{
#if DEBUG
this.AttachDevTools(new KeyGesture(Key.F12, KeyModifiers.Control));
#endif
//TransparencyLevelHint = WindowTransparencyLevel.AcrylicBlur;
}
public void CloseWithResult()
{
Close(DialogResult);
}
public virtual void ResetDataContext()
{
var old = DataContext;
DataContext = null;
DataContext = old;
}
}
}
|