Skip to content

Commit 5af1e90

Browse files
committed
Update ThemedIcon.Properties.cs
1 parent 7aca790 commit 5af1e90

File tree

1 file changed

+68
-287
lines changed

1 file changed

+68
-287
lines changed
Lines changed: 68 additions & 287 deletions
Original file line numberDiff line numberDiff line change
@@ -1,296 +1,77 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4-
using Microsoft.UI.Xaml;
54
using Microsoft.UI.Xaml.Controls;
65
using Microsoft.UI.Xaml.Media;
76

87
namespace Files.App.Controls
98
{
10-
public partial class ThemedIcon : Control
11-
{
12-
#region DEPENDENCY PROPERTY REGISTRATION
13-
14-
// Path data string properties
15-
16-
/// <summary>
17-
/// The backing <see cref="DependencyProperty"/> for the <see cref="FilledIconData"/> property.
18-
/// </summary>
19-
public static readonly DependencyProperty FilledIconDataProperty =
20-
DependencyProperty.Register(
21-
nameof(FilledIconData),
22-
typeof(string),
23-
typeof(ThemedIcon),
24-
new PropertyMetadata(string.Empty, (d, e) => ((ThemedIcon)d).OnFilledIconPropertyChanged((string)e.OldValue, (string)e.NewValue)));
25-
26-
/// <summary>
27-
/// The backing <see cref="DependencyProperty"/> for the <see cref="OutlineIconData"/> property.
28-
/// </summary>
29-
public static readonly DependencyProperty OutlineIconDataProperty =
30-
DependencyProperty.Register(
31-
nameof(OutlineIconData),
32-
typeof(string),
33-
typeof(ThemedIcon),
34-
new PropertyMetadata(string.Empty, (d, e) => ((ThemedIcon)d).OnOutlineIconPropertyChanged((string)e.OldValue, (string)e.NewValue)));
35-
36-
// Color properties
37-
38-
/// <summary>
39-
/// The backing <see cref="DependencyProperty"/> for the <see cref="Color"/> property.
40-
/// </summary>
41-
public static readonly DependencyProperty ColorProperty =
42-
DependencyProperty.Register(
43-
nameof(Color),
44-
typeof(Brush),
45-
typeof(ThemedIcon),
46-
new PropertyMetadata(null, (d, e) => ((ThemedIcon)d).OnColorPropertyChanged((Brush)e.OldValue, (Brush)e.NewValue)));
47-
48-
// Enum properties
49-
50-
/// <summary>
51-
/// The backing <see cref="DependencyProperty"/> for the <see cref="IconType"/> property.
52-
/// </summary>
53-
public static readonly DependencyProperty IconTypeProperty =
54-
DependencyProperty.Register(
55-
nameof(IconType),
56-
typeof(ThemedIconTypes),
57-
typeof(ThemedIcon),
58-
new PropertyMetadata(ThemedIconTypes.Layered, (d, e) => ((ThemedIcon)d).OnIconTypePropertyChanged((ThemedIconTypes)e.OldValue, (ThemedIconTypes)e.NewValue)));
59-
60-
/// <summary>
61-
/// The backing <see cref="DependencyProperty"/> for the <see cref="IconColorType"/> property.
62-
/// </summary>
63-
public static readonly DependencyProperty IconColorTypeProperty =
64-
DependencyProperty.Register(
65-
nameof(IconColorType),
66-
typeof(ThemedIconColorType),
67-
typeof(ThemedIcon),
68-
new PropertyMetadata(ThemedIconColorType.None, (d, e) => ((ThemedIcon)d).OnIconColorTypePropertyChanged((ThemedIconColorType)e.OldValue, (ThemedIconColorType)e.NewValue)));
69-
70-
// Double properties
71-
72-
public static readonly DependencyProperty IconSizeProperty =
73-
DependencyProperty.Register(
74-
nameof(IconSize),
75-
typeof(double),
76-
typeof(ThemedIcon),
77-
new PropertyMetadata((double)16, (d, e) => ((ThemedIcon)d).OnIconSizePropertyChanged((double)e.OldValue, (double)e.NewValue)));
78-
79-
// Boolean properties
80-
81-
/// <summary>
82-
/// The backing <see cref="DependencyProperty"/> for the <see cref="IsToggled"/> property.
83-
/// </summary>
84-
public static readonly DependencyProperty IsToggledProperty =
85-
DependencyProperty.Register(
86-
nameof(IsToggled),
87-
typeof(bool),
88-
typeof(ThemedIcon),
89-
new PropertyMetadata(defaultValue: false, (d, e) => ((ThemedIcon)d).OnIsToggledPropertyChanged((bool)e.OldValue, (bool)e.NewValue)));
90-
91-
/// <summary>
92-
/// The backing <see cref="DependencyProperty"/> for the <see cref="IsFilled"/> property.
93-
/// </summary>
94-
public static readonly DependencyProperty IsFilledProperty =
95-
DependencyProperty.Register(
96-
nameof(IsFilled),
97-
typeof(bool),
98-
typeof(ThemedIcon),
99-
new PropertyMetadata(defaultValue: false, (d, e) => ((ThemedIcon)d).OnIsFilledPropertyChanged((bool)e.OldValue, (bool)e.NewValue)));
100-
101-
/// <summary>
102-
/// The backing <see cref="DependencyProperty"/> for the <see cref="IsHighContrast"/> property.
103-
/// </summary>
104-
public static readonly DependencyProperty IsHighContrastProperty =
105-
DependencyProperty.Register(
106-
nameof(IsHighContrast),
107-
typeof(bool),
108-
typeof(ThemedIcon),
109-
new PropertyMetadata(defaultValue: false, (d, e) => ((ThemedIcon)d).OnIsHighContrastPropertyChanged((bool)e.OldValue, (bool)e.NewValue)));
110-
111-
// Layers
112-
113-
/// <summary>
114-
/// The backing <see cref="DependencyProperty"/> for the <see cref="Layers"/> property.
115-
/// </summary>
116-
public static readonly DependencyProperty LayersProperty =
117-
DependencyProperty.Register(
118-
nameof(Layers),
119-
typeof(object),
120-
typeof(ThemedIcon),
121-
new PropertyMetadata(null, (d, e) => ((ThemedIcon)d).OnLayersPropertyChanged((object)e.OldValue, (object)e.NewValue)));
122-
123-
#endregion
124-
125-
#region PUBLIC PROPERTIES
126-
127-
// Public path data string properties
128-
129-
/// <summary>
130-
/// Gets or sets the Filled Icon Path data as a String
131-
/// </summary>
132-
public string FilledIconData
133-
{
134-
get => (string)GetValue(FilledIconDataProperty);
135-
set => SetValue(FilledIconDataProperty, value);
136-
}
137-
138-
/// <summary>
139-
/// Gets or sets the Outline Icon Path data as a String
140-
/// </summary>
141-
public string OutlineIconData
142-
{
143-
get => (string)GetValue(OutlineIconDataProperty);
144-
set => SetValue(OutlineIconDataProperty, value);
145-
}
146-
147-
// Public color properties
148-
149-
/// <summary>
150-
/// Gets or sets the Brush used for the Custom IconColorType
151-
/// </summary>
152-
public Brush Color
153-
{
154-
get => (Brush)GetValue(ColorProperty);
155-
set => SetValue(ColorProperty, value);
156-
}
157-
158-
// Public enum properties
159-
160-
/// <summary>
161-
/// Gets or sets an Enum value to choose from our three icon types, Outline, Filled, Layered
162-
/// </summary>
163-
public ThemedIconTypes IconType
164-
{
165-
get => (ThemedIconTypes)GetValue(IconTypeProperty);
166-
set => SetValue(IconTypeProperty, value);
167-
}
168-
169-
/// <summary>
170-
/// Gets or sets Enum values to choose from our icon states, Normal, Critical, Caution, Success, Neutral, Disabled
171-
/// </summary>
172-
public ThemedIconColorType IconColorType
173-
{
174-
get => (ThemedIconColorType)GetValue(IconColorTypeProperty);
175-
set => SetValue(IconColorTypeProperty, value);
176-
}
177-
178-
// Public double properties
179-
180-
// <summary>
181-
/// Gets or sets a value indicating the Icon's design size.
182-
/// </summary>
183-
public double IconSize
184-
{
185-
get => (double)GetValue(IconSizeProperty);
186-
set => SetValue(IconSizeProperty, value);
187-
}
188-
189-
// Public boolean properties
190-
191-
/// <summary>
192-
/// Gets or sets a value indicating whether the Icon should use Toggled states.
193-
/// </summary>
194-
public bool IsToggled
195-
{
196-
get => (bool)GetValue(IsToggledProperty);
197-
set => SetValue(IsToggledProperty, value);
198-
}
199-
200-
/// <summary>
201-
/// Gets or sets a value indicating whether the Icon should use Filled states.
202-
/// </summary>
203-
public bool IsFilled
204-
{
205-
get => (bool)GetValue(IsFilledProperty);
206-
set => SetValue(IsFilledProperty, value);
207-
}
208-
209-
/// <summary>
210-
/// Gets or sets a value indicating whether the Icon is in HighContrast state.
211-
/// </summary>
212-
public bool IsHighContrast
213-
{
214-
get => (bool)GetValue(IsHighContrastProperty);
215-
set => SetValue(IsHighContrastProperty, value);
216-
}
217-
218-
// Public object properties
219-
220-
/// <summary>
221-
/// Gets or sets the objects we use as Layers for the Layered Icon.
222-
/// </summary>
223-
public object Layers
224-
{
225-
get => (object)GetValue(LayersProperty);
226-
set => SetValue(LayersProperty, value);
227-
}
228-
229-
#endregion
230-
231-
#region PROPERTY CHANGE EVENTS
232-
233-
// Path data string changed events
234-
235-
protected virtual void OnFilledIconPropertyChanged(string oldValue, string newValue)
236-
{
237-
UpdateFilledIconPath();
238-
}
239-
240-
protected virtual void OnOutlineIconPropertyChanged(string oldValue, string newValue)
241-
{
242-
UpdateOutlineIconPath();
243-
}
244-
245-
// Color changed events
246-
protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue)
247-
{
248-
UpdateIconTypeStates();
249-
}
250-
251-
// Enum changed events
252-
253-
protected virtual void OnIconTypePropertyChanged(ThemedIconTypes oldValue, ThemedIconTypes newValue)
254-
{
255-
UpdateIconTypeStates();
256-
}
257-
258-
protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldValue, ThemedIconColorType newValue)
259-
{
260-
UpdateIconColorTypeStates();
261-
}
262-
263-
// Double changed events
264-
265-
protected virtual void OnIconSizePropertyChanged(double oldValue, double newValue)
266-
{
267-
IconSizePropertyChanged(newValue);
268-
}
269-
270-
// Boolean changed events
271-
272-
protected virtual void OnIsToggledPropertyChanged(bool oldValue, bool newValue)
273-
{
274-
ToggleChanged(newValue);
275-
}
276-
277-
protected virtual void OnIsFilledPropertyChanged(bool oldValue, bool newValue)
278-
{
279-
FilledChanged(newValue);
280-
}
281-
282-
protected virtual void OnIsHighContrastPropertyChanged(bool oldValue, bool newValue)
283-
{
284-
HighContrastChanged(newValue);
285-
}
286-
287-
// Object changed events
288-
289-
protected virtual void OnLayersPropertyChanged(object oldValue, object newValue)
290-
{
291-
UpdateLayeredIconContent();
292-
}
293-
294-
#endregion
295-
}
9+
[DependencyProperty<string>("FilledIconData", nameof(OnFilledIconPropertyChanged))]
10+
[DependencyProperty<string>("OutlineIconData", nameof(OnOutlineIconPropertyChanged))]
11+
[DependencyProperty<Brush>("Color", nameof(OnColorPropertyChanged))]
12+
[DependencyProperty<ThemedIconTypes>("IconType", nameof(OnIconTypePropertyChanged), DefaultValue = "ThemedIconTypes.Layered")]
13+
[DependencyProperty<ThemedIconColorType>("IconColorType", nameof(OnIconColorTypePropertyChanged), DefaultValue = "ThemedIconColorType.None")]
14+
[DependencyProperty<double>("IconSize", nameof(OnIconSizePropertyChanged), DefaultValue = "(double)16")]
15+
[DependencyProperty<bool>("IsToggled", nameof(OnIsToggledPropertyChanged), DefaultValue = "false")]
16+
[DependencyProperty<bool>("IsFilled", nameof(OnIsFilledPropertyChanged), DefaultValue = "false")]
17+
[DependencyProperty<bool>("IsHighContrast", nameof(OnIsHighContrastPropertyChanged), DefaultValue = "false")]
18+
[DependencyProperty<object>("Layers", nameof(OnLayersPropertyChanged))]
19+
[DependencyProperty<ToggleBehaviors>("ToggleBehavior", nameof(OnToggleBehaviorPropertyChanged))]
20+
public partial class ThemedIcon : Control
21+
{
22+
protected virtual void OnFilledIconPropertyChanged(string oldValue, string newValue)
23+
{
24+
OnFilledIconChanged();
25+
}
26+
27+
protected virtual void OnOutlineIconPropertyChanged(string oldValue, string newValue)
28+
{
29+
OnOutlineIconChanged();
30+
}
31+
32+
protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue)
33+
{
34+
OnIconTypeChanged();
35+
}
36+
37+
protected virtual void OnIconTypePropertyChanged(ThemedIconTypes oldValue, ThemedIconTypes newValue)
38+
{
39+
OnIconTypeChanged();
40+
}
41+
42+
protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldValue, ThemedIconColorType newValue)
43+
{
44+
OnIconColorTypeChanged();
45+
}
46+
47+
protected virtual void OnIconSizePropertyChanged(double oldValue, double newValue)
48+
{
49+
UpdateVisualStates();
50+
}
51+
52+
protected virtual void OnIsToggledPropertyChanged(bool oldValue, bool newValue)
53+
{
54+
UpdateVisualStates();
55+
}
56+
57+
protected virtual void OnIsFilledPropertyChanged(bool oldValue, bool newValue)
58+
{
59+
UpdateVisualStates();
60+
}
61+
62+
protected virtual void OnIsHighContrastPropertyChanged(bool oldValue, bool newValue)
63+
{
64+
UpdateVisualStates();
65+
}
66+
67+
protected virtual void OnLayersPropertyChanged(object oldValue, object newValue)
68+
{
69+
UpdateVisualStates();
70+
}
71+
72+
protected virtual void OnToggleBehaviorPropertyChanged(ToggleBehaviors oldValue, ToggleBehaviors newValue)
73+
{
74+
UpdateVisualStates();
75+
}
76+
}
29677
}

0 commit comments

Comments
 (0)