question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get the ToggleSwitch state's text (OnContent/OffContent)

See original GitHub issue

In UWP apps it is possible to set the On/Off text for a ToggleSwitch control.

I can find the on/off state from the selected property. Is there a way to get the actual text (OnContent/OffContent)? It would be great if it is possible as the tests would match what is there on the UI.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
harvinderscommented, Jun 5, 2018

@timotiusmargo @hassanuz I am able to find a workaround for the issue. The reason we are not able to use UIAutomation to access the children of ToggleSwitch is the AccessibilityView value of Raw set for OffContent and OnContent properties. Pay attention to AutomationProperties.AccessibilityView="Raw" , this makes it visible to UIAutomation clients only when raw filter is used.

<ContentPresenter x:Name="OffContentPresenter"
    Grid.Row="1"
    Grid.RowSpan="3"
    Grid.Column="2"
    Opacity="0"
    Foreground="{TemplateBinding Foreground}"
    IsHitTestVisible="False"
    Content="{TemplateBinding OffContent}"
    ContentTemplate="{TemplateBinding OffContentTemplate}"
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    AutomationProperties.AccessibilityView="Raw" />
<ContentPresenter x:Name="OnContentPresenter"
    Grid.Row="1"
    Grid.RowSpan="3"
    Grid.Column="2"
    Opacity="0"
    Foreground="{TemplateBinding Foreground}"
    IsHitTestVisible="False"
    Content="{TemplateBinding OnContent}"
    ContentTemplate="{TemplateBinding OnContentTemplate}"
    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    AutomationProperties.AccessibilityView="Raw"/>

To solve this, either WinAppDriver should be using the raw filter to look at the UIAutomation tree or we can re-template the ToggleSwitch control, without the AutomationProperties.AccessibilityView="Raw".

0reactions
hassanuzcommented, Jun 5, 2018

Closing comment as original issue has been addressed - and workaround has been found.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get the ToggleSwitch state's text (OnContent ...
In UWP apps it is possible to set the On/Off text for a ToggleSwitch control. I can find the on/off state from the...
Read more >
How to get the switch toggle state(true/false) in javascript
The jquery if condition will give you that: var switchStatus = false; $("#togBtn").on('change', function() { if ($(this).is(':checked')) ...
Read more >
Should a toggle button show its current state or the state to ...
Use the action as the text of the toggle button, not the state. Make sure the button isn't highlighted. Highlight the action on...
Read more >
Toggle Button - Ignition
In the Property Editor, select All for the filter properties. Now you will be able to change the text based on state, but...
Read more >
Toggle-Switch Guidelines
Toggle switches are best used for changing the state of system functionalities and preferences. Toggles may replace two radio buttons or a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found