Skip to content

Commit 1d850c4

Browse files
author
eriklimakc
committed
chore: Add ControlExtensions.Icon support to TextBox
1 parent 0b2a7a9 commit 1d850c4

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

doc/material-controls-extensions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Below is a summary of the icon support for different controls:
99
| **Button** | ✔️ |||
1010
| **Combobox** | ✔️ |||
1111
| **PasswordBox** | ✔️ |||
12-
| **TextBox** | | ✔️ | ✔️ |
12+
| **TextBox** | ✔️ | ✔️ | ✔️ |
1313

1414

1515
This feature allows for the addition of icons on the supported controls. Icons can be added in different positions, such as `Icon`, `LeadingIcon`, and `TrailingIcon`. You can choose from various [`IconElement`](https://docs.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.iconelement)s to represent your icons, including `<BitmapIcon />`, `<FontIcon />`, `<PathIcon />`, or `<SymbolIcon />`.

src/library/Uno.Material/Extensions/ControlExtensions.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class ControlExtensions
2929
"Icon",
3030
typeof(IconElement),
3131
typeof(ControlExtensions),
32-
new PropertyMetadata(default));
32+
new PropertyMetadata(default, OnIconChanged));
3333

3434
[DynamicDependency(nameof(SetIcon))]
3535
public static IconElement GetIcon(Control obj) => (IconElement)obj.GetValue(IconProperty);
@@ -222,6 +222,14 @@ public static class ControlExtensions
222222

223223
#endregion
224224

225+
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
226+
{
227+
if (d is TextBox textBox)
228+
{
229+
textBox.SetValue(LeadingIconProperty, e.NewValue);
230+
}
231+
}
232+
225233
private static void OnElevationChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
226234
=> SurfaceTintExtensions.OnElevationChanged(element, (int)e.NewValue);
227235

src/library/Uno.Material/Styles/Controls/v2/TextBox.xaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@
467467
Content="{Binding Path=(um:ControlExtensions.LeadingIcon), RelativeSource={RelativeSource TemplatedParent}}"
468468
Command="{Binding Path=(um:ControlExtensions.LeadingCommand), RelativeSource={RelativeSource TemplatedParent}}"
469469
Visibility="{Binding Path=(um:ControlExtensions.IsLeadingIconVisible), RelativeSource={RelativeSource TemplatedParent}}"
470-
Style="{ThemeResource MaterialLeadingIconStyle}"
470+
Style="{StaticResource MaterialLeadingIconStyle}"
471471
HorizontalAlignment="Center"
472472
Margin="0,0,16,0"
473473
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
@@ -530,7 +530,7 @@
530530
Content="{Binding Path=(um:ControlExtensions.TrailingIcon), RelativeSource={RelativeSource TemplatedParent}}"
531531
Command="{Binding Path=(um:ControlExtensions.TrailingCommand), RelativeSource={RelativeSource TemplatedParent}}"
532532
Visibility="{Binding Path=(um:ControlExtensions.IsTrailingIconVisible), RelativeSource={RelativeSource TemplatedParent}}"
533-
Style="{ThemeResource MaterialTrailingIconStyle}"
533+
Style="{StaticResource MaterialTrailingIconStyle}"
534534
HorizontalAlignment="Center"
535535
Margin="14,0,0,0"
536536
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
@@ -702,7 +702,7 @@
702702
Content="{Binding Path=(um:ControlExtensions.LeadingIcon), RelativeSource={RelativeSource TemplatedParent}}"
703703
Command="{Binding Path=(um:ControlExtensions.LeadingCommand), RelativeSource={RelativeSource TemplatedParent}}"
704704
Visibility="{Binding Path=(um:ControlExtensions.IsLeadingIconVisible), RelativeSource={RelativeSource TemplatedParent}}"
705-
Style="{ThemeResource MaterialLeadingIconStyle}"
705+
Style="{StaticResource MaterialLeadingIconStyle}"
706706
HorizontalAlignment="Center"
707707
Margin="0,0,16,0"
708708
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
@@ -764,7 +764,7 @@
764764
Content="{Binding Path=(um:ControlExtensions.TrailingIcon), RelativeSource={RelativeSource TemplatedParent}}"
765765
Command="{Binding Path=(um:ControlExtensions.TrailingCommand), RelativeSource={RelativeSource TemplatedParent}}"
766766
Visibility="{Binding Path=(um:ControlExtensions.IsTrailingIconVisible), RelativeSource={RelativeSource TemplatedParent}}"
767-
Style="{ThemeResource MaterialTrailingIconStyle}"
767+
Style="{StaticResource MaterialTrailingIconStyle}"
768768
HorizontalAlignment="Center"
769769
Margin="14,0,0,0"
770770
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

0 commit comments

Comments
 (0)