Radio Button Patterns in WPF?

I am trying to write an automation provider for a collection of radio buttons in a WPF application. The help files seem to indicate that I should implement a selection provider pattern for the collection, which would mean that the Radio Buttons support the Selection Item provider pattern. Unfortunately radio buttons do not seem to support any Automation patterns. Does this mean I will need to create a custom Radio Button class that implements the pattern I need to use or is there an easier way around this problem?

[550 byte] By [DavidSL] at [2008-2-16]
# 1

I am guessing you have to write a client-side provider (proxy) for the Radio button class. Since this is a .NET/Avalon control, and you need to implement the automation patterns on it, the code will reside in a client-side (meaning a separate DLL) proxy which your test scripts / automation code can then load up and let UIA know where to find the proxy for this Radio button class.

Unfortunately the code samples in the latest SDK don't have a good example of implementing a "pure" client-side proxy (by pure I mean I don't have to modify/edit the code for the custom control class, just implement the proxy in a separate DLL and somehow link these two).

If you search the MSDN docs, you'll find some information (and a very basic ConsoleWindow example for a client-side proxy).

KeeronModi at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 2

David,

I am also facing a problem to automate Radio Button in WPF.

If you have any code regarding select/deselect the Radio Button.

plz share with me.

Waiting for you mail :)........

akuhad at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 3
I am looking at the WPF RadioButton sample in the SDK, and according to UI Spy, the buttons do support SelectionItem.
PeterDonnelly-MSFT at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 4

hi peter,

thnx for replay.

I have one more question.

when I am using UI SPY to see the properties of RadioButton of my Application. It show that

Radio button dont support any of the pattern. have a look....

Pattern Availability

IsDockPatternAvailable: "False"

IsExpandCollapsePatternAvailable: "False"

IsGridItemPatternAvailable: "False"

IsGridPatternAvailable: "False"

IsInvokePatternAvailable: "False"

IsMultipleViewPatternAvailable: "False"

IsRangeValuePatternAvailable: "False"

IsSelectionItemPatternAvailable: "False"

IsSelectionPatternAvailable: "False"

IsScrollPatternAvailable: "False"

IsScrollItemPatternAvailable: "False"

IsTablePatternAvailable: "False"

IsTableItemPatternAvailable: "False"

IsTextPatternAvailable: "False"

IsTogglePatternAvailable: "False"

IsTransformPatternAvailable: "False"

IsValuePatternAvailable: "False"

IsWindowPatternAvailable: "False"

I saw the properties of radiobutton of so many applicaion but it always show false for every pattern.

but it have to support selectionItempattern.

akuhad at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 5

I will have to investigate why that is happening. But in the meantime, if you select View Control Patterns in UI Spy, you will see the patterns that are supported.

In your code, you can use TryGetCurrentPattern rather than IsPatternAvailable.

Thanks for pointing this out.

PeterDonnelly-MSFTUE at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 6
Actually, running UI Spy against the various WPF samples in the SDK, I'm able to see correct values for IsXXXPatternAvailable properties. This includes radio buttons.
PeterDonnelly-MSFTUE at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 7

hi,

i wanna to know that we can select/deselect the radio button or not.

is there any issue.

If we can then plz share some code that show how to select/deselect the radio button.

I need it. its urgent.

there is an example of listbox selection but not for radio button selection in msdn.

plz help.

akuhad at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 8
Get the SelectionItemPattern for the radio button you want to select, and call Select. The other buttons in the group will be deselected, as would happen if the user initiated the selection by clicking.
PeterDonnelly-MSFTUE at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 9

HI,

I am using the below code to select the radioButton but i am getting the error( given below in red).

It seems that radio button don't support selectionItemPattern.

I am using may CTP.

UIAUTOMATION CODE:

-

AutomationElement alcf = null;

PropertyCondition condscf = new PropertyCondition(AutomationElement.NameProperty, "radiosel"); //?

alcf = AutomationElement.RootElement.FindFirst(TreeScope.Children, condscf);

if (alcf == null)

Console.WriteLine("Failed to find radiosel window");

else

Console.WriteLine("Found radiosel window");

alcf.SetFocus();

Condition cccf = new PropertyCondition(AutomationElement.AutomationIdProperty, "radioButton1", PropertyConditionFlags.IgnoreCase);

AutomationElement clcf = null;

clcf = alcf.FindFirst(TreeScope.Element | TreeScope.Children, cccf);

if (clcf == null)

Console.WriteLine("Can't able to find --> radioButton1");

else

Console.WriteLine("find --> radiobutton1");

SelectionItemPattern ipcf;

ipcf = clcf.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;

ipcf.Select();

-

ERROR:

Found radiosel window

find --> radiobutton1

Unhandled Exception: System.InvalidOperationException: Unsupported Pattern.

at System.Windows.Automation.AutomationElement.GetCurrentPattern(AutomationPa

ttern pattern)

at TVwizard_Automation.Program.Main(String[] args) in C:\Documents and Settin

gs\akuhad\My Documents\Visual Studio 2005\Projects\TVwizard_Automation\TVwizard_

Automation\Program.cs:line 43

Press any key to continue . . .

akuhad at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 10

>>>I am using may CTP.

Please try with later bits and let us know if you are still encountering this error. I am unable to reproduce it.

PeterDonnelly-MSFTUE at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 11
Hi,
Have you implemented the selection provider in the program that you are trying to control? The generic radio buttons do not atuomatically support any providers and so will not return any kind of control patterns unless you set them up specifically.
DavidSL at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...
# 12

>>>The generic radio buttons do not automatically support any providers and so will not return any kind of control patterns unless you set them up specifically<<<

Most of the standard Win32 controls are supported by client-side providers, and all WPF controls have native support for UI Automation. There is no need for client applications to do anything on the provider side.

Again, using recent bits, if you run the RadioButton WPF sample and examine it with UISpy, you will see that the radio buttons support SelectionItemPattern.

PeterDonnelly-MSFTUE at 2007-10-8 > top of Msdn Tech,Software Development for Windows Vista,Microsoft UI Automation...

Software Development for Windows Vista

Site Classified