This is a migrated thread and some comments may be shown as answers.

AutomationIDs for diagrams and nodes

1 Answer 62 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Valentina
Top achievements
Rank 1
Valentina asked on 22 Mar 2017, 08:47 PM

How can I specify AutomationIDs for Panes, Diagrams, and Nodes created at run-time in a project with MVVM architecture?  Is there any example available?

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 24 Mar 2017, 11:19 AM
Hello,

When an element is dynamically created this makes it harder to set an AutomationId automatically. The AutomationId is an attached dependency property and you can set a binding on it which will solve this issue. What you need to do basically is to create a style targeting the element you would like to apply an AutomationId to. Please take a look at the code below for example:
<Window.Resources>
        <Style TargetType="telerik:RadDiagramConnection">
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Content}">
            </Setter>
        </Style>
        <Style TargetType="telerik:RadDiagramShape">
            <Setter Property="ToolTip" Value="{Binding Content}" />
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Content}">
            </Setter>
            <Setter Property="Position" Value="{Binding Position, Mode=TwoWay}" />
 
            <Setter Property="common:AttachedProperties.Connectors" Value="{Binding MyConnectors}" />
        </Style>
As for setting an AutomationId to the Diagram simply set it's AutomationId property:
AutomationProperties.AutomationId="DiagramAutomationID"

Hope this helps.

Regards,
Peshito
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
Diagram
Asked by
Valentina
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or