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

UI Automation for RadRibbonContextualGroup

1 Answer 100 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Igorious asked on 25 Sep 2014, 09:07 AM
I have ribbon with contextual tabs.

01.<telerik:RadRibbonWindow x:Class="WpfApp.MainWindow"
04.        xmlns:telerik=""
05.        Title="MainWindow" Height="350" Width="525">
06.    <telerik:RadRichTextBoxRibbonUI>
07.        <telerik:RadRibbonTab Header="Tab1">
08.            <telerik:RadRibbonGroup Header="BBB">
09.                <telerik:RadToggleButton Name="ToggleButton" Content="Show" />
10.            </telerik:RadRibbonGroup>
11.        </telerik:RadRibbonTab>
13.        <telerik:RadRibbonTab ContextualGroupName="TestTab" Header="Tab2">
14.            <telerik:RadRibbonGroup Header="AAA">
15.                <telerik:RadRadioButton Name="TARGET_BUTTON" Content="ClickMe" />
16.            </telerik:RadRibbonGroup>
17.        </telerik:RadRibbonTab>
19.        <telerik:RadRichTextBoxRibbonUI.ContextualGroups>
20.            <telerik:RadRibbonContextualGroup Header="Test" IsActive="{Binding IsChecked, ElementName=ToggleButton}" Color="BlueViolet" GroupName="TestTab" />
21.        </telerik:RadRichTextBoxRibbonUI.ContextualGroups>
22.    </telerik:RadRichTextBoxRibbonUI>

 I try get access to element with name "TARGET_BUTTON" with UI Automation API.
01.var app = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "My Application"));
02.var allChildren = TreeWalker.RawViewWalker.GetParent(app).FindAll(TreeScope.Descendants, Condition.TrueCondition);
04.foreach (AutomationElement automationElement in allChildren)
06.    try
07.    {
08.        if (automationElement.Current.AutomationId == "TARGET_BUTTON")
09.        {
10.            Console.WriteLine("{0} ({1})", automationElement.Current.ClassName, automationElement.Current.AutomationId);
11.        }                  
12.    }
13.    catch { }

But this code don't find the button.
If I set in line 20 IsActive="true" then I can find the button.
I use last version of UI for WPF.

1 Answer, 1 is accepted

Sort by
Kiril Vandov
Telerik team
answered on 29 Sep 2014, 12:38 PM
Hello Igorious,

The RadRibbonView loads only its selected tab content. When you try to find an element in a RadRibbonTab which is not selected (as in your case) the content is not yet loaded and that is why such element can't be found. Also please note that until the ContextualGroup is active the peers for its children (RadRibbonGroup, buttons, e.t.) are not yet created and that is why you can not find the searched element. When you set the IsActive property of the ContextualGroup the RadRibbonView automatically selects the first tab in that group and that is why in this case you can find the element.

I hope this information helps.

Kind regards,
Kiril Vandov
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
RibbonView and RibbonWindow
Asked by
Top achievements
Rank 1
Answers by
Kiril Vandov
Telerik team
Share this question