WPF 在 TabItems 问题之间导航

WPF navigating between TabItems issue

我在 TabItem 中有这个 DataGrid:

        <TabControl x:Name="MainTab" FontSize="12" IsSynchronizedWithCurrentItem="True" SelectionChanged="MainTab_SelectionChanged">
    <TabItem x:Name="tabAddDocs" Header=Add Docs"></TabItem>
    <TabItem x:Name="tabEmpList" Header="Employee List">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="70*"/>
                <ColumnDefinition Width="30*"/>
            </Grid.ColumnDefinitions>
            <DataGrid x:Name="empGrid" HorizontalAlignment="Left" VerticalAlignment="Top"  
                  SelectionMode="Single" AlternatingRowBackground="#FFCDCDCD" AutoGenerateColumns="True" 
                  AutoGeneratingColumn="empGrid_AutoGeneratingColumn" FlowDirection="RightToLeft" 
                  FontSize="14" IsReadOnly="True" MouseDoubleClick="empGrid_MouseDoubleClick" 
                  Loaded="empGrid_Loaded" Focusable="False" IsEnabled="False"/>
            <Button Grid.Column="1" Name="btnJump" Click="btnJump_Click">Jump</Button>
        </Grid>
    </TabItem>
</TabControl>

我希望当我双击 DataGrid 时会显示另一个选项卡,所以我使用了这个方法:

private void empGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        tabAddDocs.IsSelected = true;
    }

但是没有任何反应。 当我按下 'btnJump' 按钮时,会触发此事件:

        private void btnJump_Click(object sender, RoutedEventArgs e)
    {
        tabAddDocs.IsSelected = true;
    }

这里真正显示了标签。

有什么区别? 我该如何解决?

谢谢!

如果您怀疑这是一个 focus/other 行为问题,请稍后尝试将选择分派:

private void btnJump_Click(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke((Action)delegate {tabAddDocs.IsSelected = true;}, 
                           DispatcherPriority.ApplicationIdle);
}