Skip to content

Commit 64c8c30

Browse files
committed
Updated code as requested
Resolved requests from @marcelwgn
1 parent 2224cb1 commit 64c8c30

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/Files.App.Controls/ThemedIcon/Data/ThemedIconToggleBehaviors.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace Files.App.Controls
99
public enum ToggleBehaviors
1010
{
1111
/// <summary>
12-
/// Toggle Behavior type of <see cref="ThemedIcon"/> is Auto.
12+
/// Auto enables the ThemedIcon to listen to owner control states.
1313
/// </summary>
1414
Auto,
1515

1616
/// <summary>
17-
/// Toggle Behavior type of <see cref="ThemedIcon"/> is On.
17+
/// On will always use the ThemedIcon's Toggle state
1818
/// </summary>
1919
On,
2020

2121
/// <summary>
22-
/// Toggle Behavior type of <see cref="ThemedIcon"/> is Off.
22+
/// Off will not use the ThemedIcon's Toggle state
2323
/// </summary>
2424
Off,
2525
}

src/Files.App.Controls/ThemedIcon/ThemedIcon.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@ namespace Files.App.Controls
1515
/// A control for a State and Color aware Icon
1616
/// </summary>
1717
public partial class ThemedIcon : Control
18-
{
18+
{
19+
private Viewbox? _filledViewBox;
20+
private Viewbox? _outlineViewBox;
21+
private Viewbox? _layeredViewBox;
22+
private Canvas? _layeredCanvas;
23+
1924
public ThemedIcon()
2025
{
2126
DefaultStyleKey = typeof(ThemedIcon);
2227
}
2328

2429
protected override void OnApplyTemplate()
2530
{
26-
IsEnabledChanged -= OnIsEnabledChanged;
27-
2831
base.OnApplyTemplate();
2932

3033
IsEnabledChanged += OnIsEnabledChanged;
3134

3235
_isOwnerEnabled = IsEnabled;
3336

37+
GetTemplateParts();
38+
3439
FindOwnerControlStates();
3540
OnFilledIconChanged();
3641
OnOutlineIconChanged();
@@ -40,39 +45,49 @@ protected override void OnApplyTemplate()
4045
OnIconColorTypeChanged();
4146
}
4247

48+
private void GetTemplateParts()
49+
{
50+
// Gets the template parts and sets the private fields
51+
_outlineViewBox = GetTemplateChild( OutlinePathIconViewBox ) as Viewbox;
52+
_filledViewBox = GetTemplateChild( FilledPathIconViewBox ) as Viewbox;
53+
_layeredViewBox = GetTemplateChild( LayeredPathIconViewBox ) as Viewbox;
54+
55+
_layeredCanvas = GetTemplateChild( LayeredPathCanvas ) as Canvas;
56+
}
57+
4358
// Updates paths and layers
4459

4560
private void OnFilledIconChanged()
4661
{
4762
// Updates Filled Icon from Path Data
48-
if (GetTemplateChild(FilledPathIconViewBox) is not Viewbox filledViewBox)
63+
if (_filledViewBox == null)
4964
return;
5065

51-
SetPathData(FilledIconPath, FilledIconData ?? string.Empty, filledViewBox);
66+
SetPathData(FilledIconPath, FilledIconData ?? string.Empty, _filledViewBox );
5267
}
5368

5469
private void OnOutlineIconChanged()
5570
{
5671
// Updates Outline Icon from Path Data
57-
if (GetTemplateChild(OutlinePathIconViewBox) is not Viewbox outlineViewBox)
72+
if (_outlineViewBox == null)
5873
return;
5974

60-
SetPathData(OutlineIconPath, OutlineIconData ?? string.Empty, outlineViewBox);
75+
SetPathData(OutlineIconPath, OutlineIconData ?? string.Empty, _outlineViewBox );
6176
}
6277

6378
private void OnLayeredIconChanged()
6479
{
6580
// Updates Layered Icon from it's Layers
66-
if (GetTemplateChild(LayeredPathIconViewBox) is not Viewbox layeredViewBox ||
67-
GetTemplateChild(LayeredPathCanvas) is not Canvas canvas ||
68-
Layers is not ICollection<ThemedIconLayer> layers)
69-
return;
81+
if ( _layeredViewBox == null ||
82+
_layeredCanvas == null ||
83+
Layers is not ICollection<ThemedIconLayer> layers)
84+
return;
7085

71-
canvas.Children.Clear();
86+
_layeredCanvas.Children.Clear();
7287

7388
foreach (var layer in layers)
7489
{
75-
canvas.Children.Add(
90+
_layeredCanvas.Children.Add(
7691
new ThemedIconLayer()
7792
{
7893
LayerType = layer.LayerType,
@@ -180,8 +195,8 @@ private void OnIconColorTypeChanged()
180195
}
181196

182197
// Update layered icon color
183-
if (GetTemplateChild(LayeredPathCanvas) is Canvas canvas)
184-
foreach (var layer in canvas.Children.Cast<ThemedIconLayer>())
198+
if (_layeredCanvas != null)
199+
foreach (var layer in _layeredCanvas.Children.Cast<ThemedIconLayer>())
185200
layer.IconColorType = IconColorType;
186201
}
187202
else

src/Files.App.Controls/ThemedIcon/ThemedIconLayer/ThemedIconLayer.Consts.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ namespace Files.App.Controls
3232
[TemplateVisualState(Name = CustomColorBGStateName, GroupName = IconLayerColorStateGroupName)]
3333

3434

35-
36-
3735
/// <summary>
3836
/// Displays a layer of <see cref="ThemedIcon"/> for <see cref="ThemedIconTypes.Layered"/> icon type.
3937
/// </summary>

0 commit comments

Comments
 (0)