Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 10, 2025

Problem

AutomationProperties.Name binding errors were occurring in MaterialDesign controls (NumericUpDown, TextBox, ComboBox, etc.) when HintAssist.Hint contained non-string values. Since HintAssist.Hint is of type object, binding it directly to AutomationProperties.Name (which expects a string) caused WPF binding errors in the output window.

Solution

Created a new AutomationPropertiesNameConverter in the Internal namespace that safely converts any value to a string for use with AutomationProperties.Name bindings:

  • If the value is already a string, returns it unchanged
  • For null or non-string values, returns an empty string

The converter was applied to all AutomationProperties.Name bindings that reference HintAssist.Hint across the theme files.

Changes

New Files

  • AutomationPropertiesNameConverter.cs - Internal value converter that safely converts objects to strings for AutomationProperties.Name
  • AutomationPropertiesNameConverterTests.cs - Comprehensive unit tests covering string, null, and non-string inputs

Modified Files

Applied the converter to 8 AutomationProperties.Name bindings in 7 XAML theme files:

  • MaterialDesignTheme.AutoSuggestBox.xaml
  • MaterialDesignTheme.ComboBox.xaml
  • MaterialDesignTheme.DatePicker.xaml
  • MaterialDesignTheme.NumericUpDown.xaml
  • MaterialDesignTheme.PasswordBox.xaml (2 occurrences - standard and reveal styles)
  • MaterialDesignTheme.TextBox.xaml
  • MaterialDesignTheme.TimePicker.xaml

Example Change

Before:

<Setter Property="AutomationProperties.Name" 
        Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}}" />

After:

<Setter Property="AutomationProperties.Name" 
        Value="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, 
                Converter={x:Static convertersInternal:AutomationPropertiesNameConverter.Instance}}" />

Impact

  • ✅ Eliminates binding errors when HintAssist.Hint contains non-string values
  • ✅ Improves accessibility support by ensuring AutomationProperties.Name always has a valid string value
  • ✅ No breaking changes - existing string hints continue to work as before
  • ✅ Consistent solution applied across all affected controls

Fixes #3941

Original prompt

This section details on the original issue you should resolve

<issue_title>Binding Errors on AutomationProperty.Name</issue_title>
<issue_description>### Bug explanation

In 5.3.0 release, create a new NumericUpDown control with the default style.

Observered: Binding Error on the AutomationProperties.Name property

Expected: No binding errors

I think the correct solution here is to create a value converter that can be applied to the binding. If the value is a string returning it, otherwise simply return empty string.

Version

5.3.0</issue_description>

<agent_instructions>Find all of the controls that bind the AutomationProperties.Name to HintAssist.Hint and apply the value converter to those binding.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #3945


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix binding errors on AutomationProperties.Name in NumericUpDown Fix AutomationProperties.Name binding errors for HintAssist.Hint Oct 10, 2025
Copilot AI requested a review from Keboo October 10, 2025 07:01
Copilot finished work on behalf of Keboo October 10, 2025 07:01
@Keboo Keboo marked this pull request as ready for review October 10, 2025 07:23
@Keboo Keboo added this to the 5.3.1 milestone Oct 10, 2025

namespace MaterialDesignThemes.Wpf.Converters;

public class ObjectToStringConverter : IValueConverter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rename this to AutomationPropertiesNameConverter and move to the internal namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Renamed to AutomationPropertiesNameConverter and moved to the Internal namespace in commit 9619ddc.

Copilot AI requested a review from Keboo October 11, 2025 01:00
Copilot finished work on behalf of Keboo October 11, 2025 01:00
Copilot AI and others added 5 commits October 23, 2025 20:47
Registers the 'convertersInternal' XML namespace in the DatePicker, NumericUpDown, and TimePicker theme dictionaries.
@Keboo Keboo force-pushed the copilot/fix-binding-errors-automationproperty-name branch from 9e6071d to 8aeb89c Compare October 24, 2025 04:06
@Keboo Keboo enabled auto-merge (squash) October 24, 2025 04:08
@Keboo Keboo merged commit b19d824 into master Oct 24, 2025
2 checks passed
@Keboo Keboo deleted the copilot/fix-binding-errors-automationproperty-name branch October 24, 2025 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binding Errors on AutomationProperty.Name

2 participants