Skip to content

Commit 23356c5

Browse files
CopilotKeboo
andcommitted
Add ObjectToStringConverter and apply to AutomationProperties.Name bindings
Co-authored-by: Keboo <[email protected]>
1 parent 03ee486 commit 23356c5

8 files changed

+29
-8
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
4+
namespace MaterialDesignThemes.Wpf.Converters;
5+
6+
public class ObjectToStringConverter : IValueConverter
7+
{
8+
public static readonly ObjectToStringConverter Instance = new();
9+
10+
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
11+
{
12+
if (value is string stringValue)
13+
{
14+
return stringValue;
15+
}
16+
return string.Empty;
17+
}
18+
19+
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
20+
=> throw new NotImplementedException();
21+
}

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.AutoSuggestBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<converters:OutlinedStyleActiveBorderMarginCompensationConverter x:Key="OutlinedStyleActiveBorderMarginCompensationConverter" />
2424
<converters:ElevationRadiusConverter x:Key="ElevationRadiusConverter" Multiplier="-1" />
2525
</Style.Resources>
26-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
26+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
2727
<Setter Property="DropDownBackground" Value="{DynamicResource MaterialDesign.Brush.Card.Background}" />
2828
<Setter Property="DropDownElevation" Value="Dp2" />
2929
<Setter Property="Template">

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@
884884
</ControlTemplate>
885885

886886
<Style x:Key="MaterialDesignComboBox" TargetType="{x:Type ComboBox}">
887-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
887+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
888888
<Setter Property="Background" Value="Transparent" />
889889
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ComboBox.Border}" />
890890
<Setter Property="BorderThickness" Value="0,0,0,1" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<Style.Resources>
2020
<Style x:Key="NestedTextBoxStyle" TargetType="{x:Type DatePickerTextBox}" BasedOn="{StaticResource MaterialDesignTextBox}" />
2121
</Style.Resources>
22-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
22+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
2323
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ForegroundLight}" />
2424
<Setter Property="BorderThickness" Value="0,0,0,1" />
2525
<Setter Property="CalendarStyle" Value="{StaticResource MaterialDesignDatePickerCalendarPortrait}" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.NumericUpDown.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
TargetType="{x:Type ButtonBase}"
3434
BasedOn="{StaticResource MaterialDesignNumericUpDownButtonsStyle}" />
3535
</Style.Resources>
36-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
36+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
3737
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ForegroundLight}" />
3838
<Setter Property="BorderThickness" Value="0,0,0,1" />
3939
<Setter Property="DecreaseContent" Value="{StaticResource ContentDecrease}" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PasswordBox.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</Style>
5252
</Style.Resources>
5353
<Setter Property="AllowDrop" Value="true" />
54-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
54+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
5555
<Setter Property="Background" Value="Transparent" />
5656
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ForegroundLight}" />
5757
<Setter Property="BorderThickness" Value="0,0,0,1" />
@@ -609,7 +609,7 @@
609609
</Style>
610610
</Style.Resources>
611611
<Setter Property="AllowDrop" Value="true" />
612-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
612+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
613613
<Setter Property="Background" Value="Transparent" />
614614
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ForegroundLight}" />
615615
<Setter Property="BorderThickness" Value="0,0,0,1" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBox.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<convertersInternal:TextBoxHorizontalScrollBarWidthConverter x:Key="TextBoxHorizontalScrollBarWidthConverter" />
5454
</Style.Resources>
5555

56-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
56+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
5757
<Setter Property="AllowDrop" Value="true" />
5858
<Setter Property="Background" Value="Transparent" />
5959
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.TextBox.Border}" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TimePicker.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Style.Resources>
1212
<Style x:Key="NestedTextBoxStyle" TargetType="wpf:TimePickerTextBox" BasedOn="{StaticResource MaterialDesignTextBox}" />
1313
</Style.Resources>
14-
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />
14+
<Setter Property="AutomationProperties.Name" Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={x:Static converters:ObjectToStringConverter.Instance}}" />
1515
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesign.Brush.ForegroundLight}" />
1616
<Setter Property="BorderThickness" Value="0,0,0,1" />
1717
<Setter Property="ClockHostContentControlStyle">

0 commit comments

Comments
 (0)