ControlTemplate取自Microsoft's website
<Window.Resources>
<ControlTemplate x:Key="TabTemplate" TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="0,0,1,1" BorderBrush="#D0CEBF" Grid.Row="1">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter ContentSource="SelectedContent"/>
</Border>
</Border>
</Border>
<TabPanel Grid.Row="0" IsItemsHost="true"/>
</Grid>
</ControlTemplate>
</Window.Resources>
<TabControl x:Key="TabTemplate">
<TabItem Header="Header">
<TextBlock Focusable="True" Text="Some text"/>
</TabItem>
</TabControl>
如果我从TabControl中删除x:Key="TabTemplate"
,则屏幕阅读器会读取内容。
我应该向ControlTemplate添加一些内容以使其可用于屏幕阅读器吗?
答案 0 :(得分:0)
<ControlTemplate x:Key="TabTemplate" TargetType="TabControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderThickness="0,0,1,1" BorderBrush="#D0CEBF" Grid.Row="1">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
</Border>
</Border>
</Border>
<TabPanel Grid.Row="0" IsItemsHost="true"/>
</Grid>
</ControlTemplate>
技巧是ContentPresenter的x:Name
属性。屏幕阅读器的行为应正好PART_SelectedContentHost
。