forked from MaterialDesignInXAML/MaterialDesignInXamlToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListSortDirectionIndicator.cs
More file actions
68 lines (54 loc) · 2.67 KB
/
Copy pathListSortDirectionIndicator.cs
File metadata and controls
68 lines (54 loc) · 2.67 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
60
61
62
63
64
65
66
67
68
using System.ComponentModel;
namespace MaterialDesignThemes.Wpf;
[TemplateVisualState(GroupName = DirectionGroupName, Name = NoneStateName)]
[TemplateVisualState(GroupName = DirectionGroupName, Name = AscendingStateName)]
[TemplateVisualState(GroupName = DirectionGroupName, Name = DescendingStateName)]
public class ListSortDirectionIndicator : Control
{
public const string DirectionGroupName = "Direction";
public const string NoneStateName = "None";
public const string AscendingStateName = "Ascending";
public const string DescendingStateName = "Descending";
static ListSortDirectionIndicator()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ListSortDirectionIndicator), new FrameworkPropertyMetadata(typeof(ListSortDirectionIndicator)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
GotoVisualState(true, ListSortDirection);
}
public static readonly DependencyProperty ListSortDirectionProperty = DependencyProperty.Register(
nameof(ListSortDirection), typeof(ListSortDirection?), typeof(ListSortDirectionIndicator), new PropertyMetadata(default(ListSortDirection?), ListSortDirectionPropertyChangedCallback));
private static void ListSortDirectionPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
var indicator = (ListSortDirectionIndicator)dependencyObject;
indicator.GotoVisualState(true, indicator.ListSortDirection);
indicator.IsNeutral = !indicator.ListSortDirection.HasValue;
}
public ListSortDirection? ListSortDirection
{
get { return (ListSortDirection?)GetValue(ListSortDirectionProperty); }
set { SetValue(ListSortDirectionProperty, value); }
}
private static readonly DependencyPropertyKey IsNeutralPropertyKey =
DependencyProperty.RegisterReadOnly(
"IsNeutral", typeof(bool), typeof(ListSortDirectionIndicator),
new PropertyMetadata(true));
public static readonly DependencyProperty IsNeutralProperty =
IsNeutralPropertyKey.DependencyProperty;
public bool IsNeutral
{
get { return (bool)GetValue(IsNeutralProperty); }
private set { SetValue(IsNeutralPropertyKey, value); }
}
private void GotoVisualState(bool useTransitions, ListSortDirection? direction)
{
var stateName = direction.HasValue
? (direction.Value == System.ComponentModel.ListSortDirection.Ascending
? AscendingStateName
: DescendingStateName)
: NoneStateName;
VisualStateManager.GoToState(this, stateName, useTransitions);
}
}