Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automation problem in v7 #674

Closed
znakeeye opened this issue Nov 29, 2018 · 4 comments
Closed

Automation problem in v7 #674

znakeeye opened this issue Nov 29, 2018 · 4 comments

Comments

@znakeeye
Copy link

znakeeye commented Nov 29, 2018

Consider the following tab item:

<fluent:RibbonTabItem Header="Home"
                      AutomationProperties.AutomationId="aid_HomeTab" />

In older versions (v3.6) the AutomationId of the underlying Label element (below the PART_ContentContainer) was set to homeTabItem. This behavior changed a bit in v7. Now, there is no Label. Instead, there is a ContentControl (with AutomationId set) but its underlying TextBlock has no AutomationId. This implies that tools such as Microsoft Inspect cannot see the text element. Only the tab item is visible.

Ideally, the TextBlock would get the same AutomationId as the RibbonTabItem. Not sure how to propagate the value. Neither TemplateBinding nor Binding... TemplatedParent works.

<Style TargetType="{x:Type fluent:RibbonTabItem}" BasedOn="{StaticResource RibbonTabItemStyle}">
  <Setter Property="HeaderTemplate">
    <Setter.Value>
          <DataTemplate>
              <!-- Here I want the ID of the RibbonTabItem -->
              <TextBlock VerticalAlignment="Center"
                         HorizontalAlignment="Left"
                         Text="{Binding}"
                         TextWrapping="NoWrap"
                         TextTrimming="None"
                         AutomationProperties.AutomationId="Test"/>
          </DataTemplate>
      </Setter.Value>
  </Setter>
</Style>

I believe the major problem is that the RibbonTabItem doesn't show up in Inspect.


Environment

  • Fluent.Ribbon v7.0.0-alpha0456
  • Windows 10
  • .NET Framework 4.5.2
@znakeeye
Copy link
Author

So in RibbonTabItemControlTemplate you have this:

<ContentControl AutomationProperties.Name="{TemplateBinding Header}"
                AutomationProperties.AutomationId="{TemplateBinding Name}"
                Content="{TemplateBinding Header}"
                ContentTemplate="{TemplateBinding HeaderTemplate}"
		...

Perhaps you should instead set Content="{TemplateBinding}" allowing the DataTemplate to bind to more than just the text?

@znakeeye
Copy link
Author

I found a really hacky solution:

<Style TargetType="{x:Type fluent:RibbonTabItem}" BasedOn="{StaticResource RibbonTabItemStyle}">
  <Setter Property="HeaderTemplate">
    <Setter.Value>
      <DataTemplate>
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding}" TextWrapping="NoWrap" TextTrimming="None"
                   AutomationProperties.AutomationId="{Binding Path=(AutomationProperties.AutomationId),RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ContentControl}}}"/>
      </DataTemplate>
    </Setter.Value>
  </Setter>
</Style>

Please consider a better fix. E.g. setting Content to a more complex structure than just a string.

@batzen
Copy link
Member

batzen commented Nov 29, 2018

Header is of type object already, so i don't know what i should fix there.

Adding a custom automation peer for RibbonTabItem is part of #647 already.

@znakeeye
Copy link
Author

Cool! The automation peer will make life easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants