-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupBox.cs
More file actions
59 lines (48 loc) · 1.83 KB
/
GroupBox.cs
File metadata and controls
59 lines (48 loc) · 1.83 KB
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
namespace UnoGroupBox;
public sealed partial class GroupBox : ContentControl
{
public object Header
{
get => GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register(nameof(Header), typeof(object), typeof(GroupBox), new PropertyMetadata(null));
public DataTemplate HeaderTemplate
{
get => (DataTemplate) GetValue(HeaderTemplateProperty);
set => SetValue(HeaderTemplateProperty, value);
}
public static readonly DependencyProperty HeaderTemplateProperty =
DependencyProperty.Register(nameof(HeaderTemplate), typeof(DataTemplate), typeof(GroupBox), new PropertyMetadata(null));
public GroupBoxTheme Theme
{
get => (GroupBoxTheme) GetValue(ThemeProperty);
set => SetValue(ThemeProperty, value);
}
public static readonly DependencyProperty ThemeProperty =
DependencyProperty.Register(nameof(Theme), typeof(GroupBoxTheme), typeof(GroupBox),
new PropertyMetadata(GroupBoxTheme.Fluent, OnThemeChanged));
public GroupBox()
{
DefaultStyleKey = typeof(GroupBox);
}
private static void OnThemeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is GroupBox gb)
{
string state = (GroupBoxTheme) e.NewValue == GroupBoxTheme.Material ? "Material" : "Fluent";
gb.Loaded += (s, _) => VisualStateManager.GoToState(gb, state, true);
VisualStateManager.GoToState(gb, state, true);
}
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
ApplyTheme();
}
void ApplyTheme()
{
VisualStateManager.GoToState(this, Theme == GroupBoxTheme.Material ? "Material" : "Fluent", true);
}
}