Open aronweiler opened 2 years ago
Some additional information:
I forked your repo and found that I can easily add a DependencyProperty
(example below) that allows me to add AutomationId
s to the control, but while this works for the buttons that are specified for the ContentDialog
, I have as of yet been unable to specify an AutomationId
for the title of the dialog.
I did some research around automation and custom WPF controls, and it appears as if there is additional work that probably needs to be done in order to properly flow the AutomationId
s from the template into the control itself.
I'm not really a UI guy these days, though, so hopefully you have some idea of what needs to be done in that regard. If you know what the approach is, I can help implement it.
Here's my example of adding and using a custom AutomationId
for the buttons on the ContentDialog
control:
ContentDialog.cs
public static readonly DependencyProperty PrimaryButtonAutomationIdProperty =
DependencyProperty.Register(
nameof(PrimaryButtonAutomationId),
typeof(string),
typeof(ContentDialog),
null);
public string PrimaryButtonAutomationId
{
get => (string)GetValue(PrimaryButtonAutomationIdProperty);
set => SetValue(PrimaryButtonAutomationIdProperty, value);
}
ContentDialog.xaml
<Button
x:Name="PrimaryButton"
Content="{TemplateBinding PrimaryButtonText}"
IsEnabled="{TemplateBinding IsPrimaryButtonEnabled}"
Style="{TemplateBinding PrimaryButtonStyle}"
AutomationProperties.AutomationId="{TemplateBinding PrimaryButtonAutomationId}"
HorizontalAlignment="Stretch" />
First, let me thank you for the excellent work you've done here on this UI framework- it's a huge improvement over the standard WPF stuff and/or building this myself.
I would, however, like to know if it is possible to set the
AutomationId
of various controls. I automated the testing of the user interface with WinAppDriver, and like most UI test frameworks, it uses theAutomationId
of the controls to find them.I am using the NuGet version
0.9.6
of your library.Here is what I am trying to accomplish.
Take this Power Dialog for example:
As you can see, I am setting the
AutomationProperties.AutomationId="power dialog"
value... however, that AutomationId never makes it to the actual UI (I verify this using the Inspect tool).I want to set the
AutomationId
s for the buttons on this dialog, as well, but there does not appear to be a way to accomplish that. The buttons on the dialog DO come withAutomationId
s already set, but they don't appear accessible to me. For instance, the cancel button shown above has anAutomationId
ofCloseButton
.Any help on this would be appreciated.
Thanks,
Aron