我有控制模板,在这里:
<ControlTemplate x:Key="DialogWindowTemplate" TargetType="{x:Type w:DialogWindow}">
<Border d:DesignHeight="500" d:DesignWidth="700" CornerRadius="5" Background="{StaticResource ContrastWhiteBrush}"
BorderThickness="1" BorderBrush="{StaticResource ContentNormalBrush}">
<Grid>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right"
VerticalAlignment="Center" Margin="10,0,10,0">
<Button Content="{TemplateBinding ActionName}" Style="{StaticResource ButtonStyle}" KeyboardNavigation.TabIndex="1"
VerticalAlignment="Center" Margin="10,0,10,0" Padding="5,0,5,0" FontWeight="Bold" Height="30" Width="75"
Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActionCommand}"/>
<TextBlock Text="{x:Static loc:Controls.Dialog_Or}" Style="{StaticResource ContentNormalFontStyle}"
VerticalAlignment="Center" Margin="0"/>
<Button Style="{StaticResource CancelButtonStyle}" VerticalAlignment="Center" Margin="10,0,10,0" KeyboardNavigation.TabIndex="2"
Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CancelCommand}"/>
</StackPanel>
</Grid>
</Border>
</ControlTemplate>
这是 .cs 文件
public DialogWindow()
{
// load the template
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(TEMPLATE_URI);
this.Resources.MergedDictionaries.Add(rd);
this.Template = this.Resources["DialogWindowTemplate"] as ControlTemplate;
this.WindowStyle = WindowStyle.None;
this.AllowsTransparency = true;
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, CloseCommandHandler));
this.CommandBindings.Add(new CommandBinding(_escCommand, CloseCommandHandler));
}
我的问题是:我尝试了所有可能的选项,但选项卡导航不适用于这些按钮。但是当我按 Ctrl + Tab 时,它就可以工作了。我也试过这个 KeyBoard.ControlTabNavigation = "None"。但它不起作用。
谢谢