简体   繁体   English

WPF:两个TabControls /切换在Win7 / .NET 4.5下工作,但在Windows 8.1 / .NET 4.5.1下不工作

[英]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.

相关问题 Library Targetting .NET 4.5.1和Windows 8.1 / WP8.1中的套接字 - Sockets in Library Targetting .NET 4.5.1 and Windows 8.1/WP8.1 c#.net4 VisualStyles是否可以使窗体控件看起来像在XP下的Vista / win7上一样? - c# .net4 VisualStyles is there a way to make a forms controls to look as they do on Vista/win7 under XP? 在标题中添加图标以进行排序在c#net 3.5下的Win7 x64上很奇怪 - Adding icons in headers for sorting acts weird on Win7 x64 under c# net 3.5 在.NET核心下的Linux上运行.NET 4.5 - Running .NET 4.5 on Linux under .NET core NET Core 2默认的“ Web应用程序”在win7下的远程IIS上失败 - NET Core 2 default 'Web Application" fails on remote IIS under win7 为Win7和Win 8 OS开发WPF .NET 3.5应用程序 - Developing WPF .NET 3.5 application for Win7 and Win 8 OS 在.NET4.5下使用ArrayList进行转换 - Casting Using ArrayList Under .NET4.5 在Win7和Win8而不是Windows 2012 R2下可运行的Process.Start() - Process.Start() working under Win7 and Win8 but not Windows 2012 R2 如何将Windows Store应用程序项目从.NET 4.5升级到.NET 4.5.1 - How can I upgrade a Windows Store App-project from .NET 4.5 to .NET 4.5.1 在Windows 8.1下以横向模式裁剪打印的WPF视觉效果 - Printed wpf visual is clipped in landscape mode under Windows 8.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM