[英]WPF: Two TabControls / Switching works under Win7/.NET 4.5 but not under Windows 8.1/.NET 4.5.1
I've got a window with two TabControls. 我有一个带有两个TabControl的窗口。 One is Left-Aligned, the other right-aligned.
一个是左对齐,另一个是右对齐。 The Headers of the TabControls are aligned in the top row.
TabControl的标题在第一行中对齐。
Whenever I click a TabItem, the other TabControl is unfocused. 每当我单击一个TabItem时,另一个TabControl就会失去焦点。
That works perfectly fine on my development PC (Windows 7, .NET Framework 4.5). 在我的开发PC(Windows 7,.NET Framework 4.5)上,这工作得很好。
However, when I execute it under a PC with Windows 8.1 (.NET 4.5.1), I can not switch to the right-aligned TabControl. 但是,当我在装有Windows 8.1(.NET 4.5.1)的PC上执行该程序时,无法切换到右对齐的TabControl。 When I click on a TabItem inside it, nothing at all happens.
当我单击其中的TabItem时,什么也没有发生。
XAML of the MainWindow: MainWindow的XAML:
<Window x:Class="TabGroupProblem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<TabControl GotFocus="TabControl_GotFocus" x:Name="c1">
<TabItem Header="One">h</TabItem>
<TabItem Header="Two">i</TabItem>
</TabControl>
<TabControl GotFocus="TabControl_GotFocus_1" x:Name="c2">
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</TabControl.Resources>
<TabItem Header="Three">j</TabItem>
<TabItem Header="four">k</TabItem>
</TabControl>
</Grid>
</Window>
Event Handlers: 事件处理程序:
private void TabControl_GotFocus(object sender, RoutedEventArgs e)
{
// c1 to foreground
System.Windows.Controls.Grid.SetZIndex(c2, -1);
c2.SelectedIndex = -1;
}
private void TabControl_GotFocus_1(object sender, RoutedEventArgs e)
{
// c2 to foreground
System.Windows.Controls.Grid.SetZIndex(c2, 1);
c1.SelectedIndex = -1;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Grid.SetZIndex(c1, 0);
System.Windows.Controls.Grid.SetZIndex(c2, -1);
c2.SelectedIndex = -1;
}
Why does that happen, and what can I do against it? 为什么会发生这种情况,我该怎么办?
edit: Switched the Target framework to .NET 4.5.1 on my development PC. 编辑:在我的开发PC上将Target框架切换到.NET 4.5.1。 Switching between TabControls still works on my PC (and still not on the Windows 8.1 PC)
在TabControls之间切换仍然可以在我的PC上运行(而在Windows 8.1 PC上仍然不行)
You are placing two TabControls directly over each other, but still expect to be able to focus the one underneath. 您将两个TabControl彼此直接直接放置,但仍希望能够将一个TabControl集中在下面。 This obviously happens to work in Win7, but it would appear Windows 8 uses a different control template that potentially eats the mouse clicks on the "blank" bit of the TabPanel.
显然,这在Win7中是可行的,但是Windows 8似乎使用了另一个控件模板,该模板有可能吞噬TabPanel的“空白”位上的鼠标单击。
Maybe it's adding a transparent brush, so you could try a simple: 也许正在添加透明画笔,所以您可以尝试以下简单方法:
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="Background" Value="{x:Null}" />
</Style>
</TabControl.Resources>
However, I suspect it would be easier to ditch the tab control and just create some styled buttons yourself? 但是,我怀疑放弃选项卡控件并自己创建一些样式的按钮会更容易吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.