Hi!
I'm doing some research for automated testing at the moment and I ran into a problem when using the UI Automation and the Automation Peers.
In a demo application I create a custom UserControl that basically only holds a Ellipse. I've then created a DependencyProperty called 'EllipseFill' that allows to set the Fill of said Ellipse. From a funtional point of view this works fine already.
I then tried to make the custom UserControl visible for UI Automation. I therefore implemented a custom AutomationPeer-claas. Now my custom UserControl is visible in Inspect, but unfortunately I fail to make the 'EllipseFill' property visible. I was not able to find a corresponding tutorial on the web - could please someone here help me out?
Here is my custom UserControl's code:
public partial class AUIEllipseUserControl : UserControl { protected override AutomationPeer OnCreateAutomationPeer() { return new AUIEllipseUserControlAutomationPeer(this); } public AUIEllipseUserControl() { InitializeComponent(); } private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { AUIEllipseUserControl aui = d as AUIEllipseUserControl; if (aui != null && (e.OldValue != e.NewValue)) { aui.InnerElipse.Fill = e.NewValue as SolidColorBrush; } } public static readonly DependencyProperty EllipseFillProperty = DependencyProperty.Register("EllipseFill", typeof(SolidColorBrush), typeof(AUIEllipseUserControl), new FrameworkPropertyMetadata(OnPropertyChanged)); public SolidColorBrush EllipseFill { get { return this.GetValue(EllipseFillProperty) as SolidColorBrush; } set { this.SetValue(EllipseFillProperty, value); } } private class AUIEllipseUserControlAutomationPeer : FrameworkElementAutomationPeer { public AUIEllipseUserControlAutomationPeer(FrameworkElement owner) : base(owner) { if (!(owner is AUIEllipseUserControl)) throw new ArgumentOutOfRangeException(); } protected override string GetClassNameCore() { return "AUIEllipseUserControl"; } protected override AutomationControlType GetAutomationControlTypeCore() { return AutomationControlType.Custom; } protected override bool IsContentElementCore() { return true; } protected override bool IsControlElementCore() { return false; } } }
Any ideas what I have to do to make the 'EllipseFill' property visible?
Regards
Ralf