diff --git a/doc/material-controls-extensions.md b/doc/material-controls-extensions.md
index 8ddadb5ca..109e64fb2 100644
--- a/doc/material-controls-extensions.md
+++ b/doc/material-controls-extensions.md
@@ -4,13 +4,14 @@
Below is a summary of the icon support for different controls:
-| Control | Icon | LeadingIcon | TrailingIcon |
-|-----------------|------|-------------|--------------|
-| **Button** | ✔️ | ❌ | ❌ |
-| **Combobox** | ✔️ | ❌ | ❌ |
-| **PasswordBox** | ✔️ | ❌ | ❌ |
-| **TextBox** | ✔️ | ✔️ | ✔️ |
-
+| Control | Icon | LeadingIcon | TrailingIcon |
+|-----------------|-------|-------------|--------------|
+| **Button** | ✔️ | ❌ | ❌ |
+| **Combobox** | ✔️ | ❌ | ❌ |
+| **PasswordBox** | ✔️ | ❌ | ❌ |
+| **TextBox** | ✔️* | ✔️ | ✔️ |
+
+\* Setting the `Icon` for a `TextBox` will simply set the `LeadingIcon`.
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 ``, ``, ``, or ``.
diff --git a/src/library/Uno.Material/Extensions/ControlExtensions.cs b/src/library/Uno.Material/Extensions/ControlExtensions.cs
index a3bd47f07..d41a5f867 100644
--- a/src/library/Uno.Material/Extensions/ControlExtensions.cs
+++ b/src/library/Uno.Material/Extensions/ControlExtensions.cs
@@ -5,6 +5,8 @@
using Windows.UI;
using Uno.Disposables;
using System.Windows.Input;
+using Uno.Extensions;
+using Microsoft.Extensions.Logging;
#if WinUI
using Microsoft.UI.Xaml;
@@ -66,12 +68,11 @@ public static class ControlExtensions
#endregion
#region DependencyProperty: LeadingIcon
-
public static DependencyProperty LeadingIconProperty { [DynamicDependency(nameof(GetLeadingIcon))] get; } = DependencyProperty.RegisterAttached(
"LeadingIcon",
typeof(IconElement),
typeof(ControlExtensions),
- new PropertyMetadata(default));
+ new PropertyMetadata(default, OnLeadingIconChanged));
[DynamicDependency(nameof(SetLeadingIcon))]
public static IconElement GetLeadingIcon(Control obj) => (IconElement)obj.GetValue(LeadingIconProperty);
@@ -79,15 +80,16 @@ public static class ControlExtensions
[DynamicDependency(nameof(GetLeadingIcon))]
public static void SetLeadingIcon(Control obj, IconElement value) => obj.SetValue(LeadingIconProperty, value);
+ private static void OnLeadingIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "LeadingIcon");
#endregion
#region DependencyProperty: IsLeadingIconVisible
-
public static DependencyProperty IsLeadingIconVisibleProperty { [DynamicDependency(nameof(GetIsLeadingIconVisible))] get; } = DependencyProperty.RegisterAttached(
"IsLeadingIconVisible",
typeof(bool),
typeof(ControlExtensions),
- new PropertyMetadata(true));
+ new PropertyMetadata(true, OnIsLeadingIconVisibleChanged));
[DynamicDependency(nameof(SetIsLeadingIconVisible))]
public static bool GetIsLeadingIconVisible(Control obj) => (bool)obj.GetValue(IsLeadingIconVisibleProperty);
@@ -95,6 +97,8 @@ public static class ControlExtensions
[DynamicDependency(nameof(GetIsLeadingIconVisible))]
public static void SetIsLeadingIconVisible(Control obj, bool value) => obj.SetValue(IsLeadingIconVisibleProperty, value);
+ private static void OnIsLeadingIconVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "IsLeadingIconVisible");
#endregion
#region DependencyProperty: LeadingCommand
@@ -102,37 +106,41 @@ public static class ControlExtensions
"LeadingCommand",
typeof(ICommand),
typeof(ControlExtensions),
- new PropertyMetadata(default));
+ new PropertyMetadata(default, OnLeadingCommandChanged));
[DynamicDependency(nameof(GetLeadingCommand))]
public static ICommand GetLeadingCommand(Control obj) => (ICommand)obj.GetValue(LeadingCommandProperty);
[DynamicDependency(nameof(SetLeadingCommand))]
public static void SetLeadingCommand(Control obj, ICommand value) => obj.SetValue(LeadingCommandProperty, value);
+
+ private static void OnLeadingCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "LeadingCommand");
#endregion
#region DependencyProperty: TrailingIcon
-
public static DependencyProperty TrailingIconProperty { [DynamicDependency(nameof(GetTrailingIcon))] get; } = DependencyProperty.RegisterAttached(
"TrailingIcon",
typeof(IconElement),
typeof(ControlExtensions),
- new PropertyMetadata(default));
+ new PropertyMetadata(default, OnTrailingIconChanged));
[DynamicDependency(nameof(SetTrailingIcon))]
public static IconElement GetTrailingIcon(Control obj) => (IconElement)obj.GetValue(TrailingIconProperty);
[DynamicDependency(nameof(GetTrailingIcon))]
public static void SetTrailingIcon(Control obj, IconElement value) => obj.SetValue(TrailingIconProperty, value);
+
+ private static void OnTrailingIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "TrailingIcon");
#endregion
#region DependencyProperty: IsTrailingIconVisible
-
public static DependencyProperty IsTrailingIconVisibleProperty { [DynamicDependency(nameof(GetIsTrailingIconVisible))] get; } = DependencyProperty.RegisterAttached(
"IsTrailingIconVisible",
typeof(bool),
typeof(ControlExtensions),
- new PropertyMetadata(true));
+ new PropertyMetadata(true, OnIsTrailingIconVisibleChanged));
[DynamicDependency(nameof(SetIsTrailingIconVisible))]
public static bool GetIsTrailingIconVisible(Control obj) => (bool)obj.GetValue(IsTrailingIconVisibleProperty);
@@ -140,6 +148,8 @@ public static class ControlExtensions
[DynamicDependency(nameof(GetIsTrailingIconVisible))]
public static void SetIsTrailingIconVisible(Control obj, bool value) => obj.SetValue(IsTrailingIconVisibleProperty, value);
+ private static void OnIsTrailingIconVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "IsTrailingIconVisible");
#endregion
#region DependencyProperty: TrailingCommand
@@ -147,13 +157,16 @@ public static class ControlExtensions
"TrailingCommand",
typeof(ICommand),
typeof(ControlExtensions),
- new PropertyMetadata(default));
+ new PropertyMetadata(default, OnTrailingCommandChanged));
[DynamicDependency(nameof(GetTrailingCommand))]
public static ICommand GetTrailingCommand(Control obj) => (ICommand)obj.GetValue(TrailingCommandProperty);
[DynamicDependency(nameof(SetTrailingCommand))]
public static void SetTrailingCommand(Control obj, ICommand value) => obj.SetValue(TrailingCommandProperty, value);
+
+ private static void OnTrailingCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ => WarnNotSupportedProperty(d, "TrailingCommand");
#endregion
#region DependencyProperty: AlternateContent
@@ -205,6 +218,7 @@ public static class ControlExtensions
public static void SetTintedBackground(UIElement obj, SolidColorBrush value) => obj.SetValue(TintedBackgroundProperty, value);
#endregion
+
#region DependencyProperty: IsTintEnabled
///
/// Gets or sets whether or not the SurfaceTintColor should be applied for elevated views
@@ -230,6 +244,14 @@ private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedE
}
}
+ private static void WarnNotSupportedProperty(DependencyObject d, string propertyName)
+ {
+ if (d is not TextBox)
+ {
+ d.Log().LogWarning($"Warning: {propertyName} is only supported on TextBox controls.");
+ }
+ }
+
private static void OnElevationChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
=> SurfaceTintExtensions.OnElevationChanged(element, (int)e.NewValue);