当自定义 ControlTemplate 应用于 TabControl 时,WPF TabItem 内容未被屏幕读取 reader
WPF TabItem contents is not read by screen reader when custom ControlTemplate is applied to TabControl
控件模板取自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"
reader 读取内容。
我是否应该向 ControlTemplate 添加一些内容以使其可用于屏幕 reader?
<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
属性。屏幕 reader 应该正好是 PART_SelectedContentHost
才能正常运行。
控件模板取自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"
reader 读取内容。
我是否应该向 ControlTemplate 添加一些内容以使其可用于屏幕 reader?
<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
属性。屏幕 reader 应该正好是 PART_SelectedContentHost
才能正常运行。