我可以使用 DataTemplate 作为工具栏按钮并且仍然使名称有意义吗?

发布于 2024-12-09 19:54:47 字数 2458 浏览 0 评论 0原文

我有一个工具栏,其 ItemSource 是工具栏项目的集合,其中包含按钮的位图文本和其他信息,并且 xaml 包含一个将数据绑定到按钮的 DataTemplate。

我们的应用程序现在需要符合 508 标准,当我运行 Accessible Event Watcher 时,它会将所有工具栏按钮名称列为“未知”。

有人可以告诉我如何为按钮提供一个有意义的名称吗?

以下是适用于此问题的 xaml 部分:

<ToolBar.ItemTemplate>
    <DataTemplate DataType="{x:Type src:toolBarItem}">
          <DataTemplate.Resources>
           <src:toolBarItemConverter x:Key="buttonConverter" />
           <src:booleanToVisibilityConverter x:Key="boolToVisibilityConverter" />
              <src:toolBarButtonFormatConverter x:Key="toolBarFormatDisplayConverter" />
              <src:stringToVisibilityConverter x:Key="stringToVisibilityDisplayConverter" />
    </DataTemplate.Resources>

    <StackPanel Orientation="Horizontal">

        <Border Style="{StaticResource SeparatorStyle}" Visibility="{Binding menuSeparator, Converter={StaticResource boolToVisibilityConverter}}"/>

        <Button x:Name="listButton" Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}" VerticalAlignment="Top" HorizontalAlignment="Center" Visibility="{Binding isActiveButton, Converter={StaticResource boolToVisibilityConverter}}" Tag="{Binding}" 
      ToolTip="{Binding menuTooltip}"  IsEnabled="{Binding isEnabled}"  >
             <UniformGrid VerticalAlignment="Center" HorizontalAlignment="Center" Rows="{Binding menuText,Converter={StaticResource toolBarFormatDisplayConverter}}" >
     <!-- button image -->
     <Image Grid.Row="0"  HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding menuImage, Converter={StaticResource buttonConverter}}"/>
     <!-- button name -->
              <Viewbox StretchDirection="DownOnly" HorizontalAlignment="Center" VerticalAlignment="Bottom" Visibility="{Binding menuText, Converter={StaticResource stringToVisibilityDisplayConverter}}" >
               <TextBlock x:Name="buttonName" FontFamily="Segoe UI" Width="{Binding menuWidth}"  FontSize="12" Grid.Row="1" TextAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding menuText}" Foreground="Black" />
     </Viewbox>
    </UniformGrid>
      <!-- </StackPanel> -->
      </Button>          
          </StackPanel>
        </DataTemplate>
   </ToolBar.ItemTemplate>

谢谢,

Ron

I have a Toolbar whose ItemSource is a collection of toolbarItems which contain the bitmap text and other info for the button and the xaml includes a DataTemplate to bind the data to the button.

Our app now needs to become 508 compliant and when I run the Accessible Event Watcher it is listing all the toolbar button names as "Unknown".

Can someone tell me how to provide a meaningful name to the buttons?

Here's the portion of xaml applying to this issue:

<ToolBar.ItemTemplate>
    <DataTemplate DataType="{x:Type src:toolBarItem}">
          <DataTemplate.Resources>
           <src:toolBarItemConverter x:Key="buttonConverter" />
           <src:booleanToVisibilityConverter x:Key="boolToVisibilityConverter" />
              <src:toolBarButtonFormatConverter x:Key="toolBarFormatDisplayConverter" />
              <src:stringToVisibilityConverter x:Key="stringToVisibilityDisplayConverter" />
    </DataTemplate.Resources>

    <StackPanel Orientation="Horizontal">

        <Border Style="{StaticResource SeparatorStyle}" Visibility="{Binding menuSeparator, Converter={StaticResource boolToVisibilityConverter}}"/>

        <Button x:Name="listButton" Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}" VerticalAlignment="Top" HorizontalAlignment="Center" Visibility="{Binding isActiveButton, Converter={StaticResource boolToVisibilityConverter}}" Tag="{Binding}" 
      ToolTip="{Binding menuTooltip}"  IsEnabled="{Binding isEnabled}"  >
             <UniformGrid VerticalAlignment="Center" HorizontalAlignment="Center" Rows="{Binding menuText,Converter={StaticResource toolBarFormatDisplayConverter}}" >
     <!-- button image -->
     <Image Grid.Row="0"  HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding menuImage, Converter={StaticResource buttonConverter}}"/>
     <!-- button name -->
              <Viewbox StretchDirection="DownOnly" HorizontalAlignment="Center" VerticalAlignment="Bottom" Visibility="{Binding menuText, Converter={StaticResource stringToVisibilityDisplayConverter}}" >
               <TextBlock x:Name="buttonName" FontFamily="Segoe UI" Width="{Binding menuWidth}"  FontSize="12" Grid.Row="1" TextAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding menuText}" Foreground="Black" />
     </Viewbox>
    </UniformGrid>
      <!-- </StackPanel> -->
      </Button>          
          </StackPanel>
        </DataTemplate>
   </ToolBar.ItemTemplate>

Thanks,

Ron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2024-12-16 19:54:47

好的,我们想通了。需要简单地将您的名字绑定到 AutomationProperties.Name

<Button x:Name="listButton" AutomationProperties.Name="{Binding menuText}" 
Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}"  
VerticalAlignment="Top" HorizontalAlignment="Center" 
Visibility="{Binding isActiveButton,  
Converter={StaticResource boolToVisibilityConverter}}" 
Tag="{Binding}" ToolTip="{Binding  menuTooltip}"  IsEnabled="{Binding isEnabled}"  >

OK we figured this out. Need to simply bind your names to the AutomationProperties.Name

<Button x:Name="listButton" AutomationProperties.Name="{Binding menuText}" 
Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}"  
VerticalAlignment="Top" HorizontalAlignment="Center" 
Visibility="{Binding isActiveButton,  
Converter={StaticResource boolToVisibilityConverter}}" 
Tag="{Binding}" ToolTip="{Binding  menuTooltip}"  IsEnabled="{Binding isEnabled}"  >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文