如何更改TabControl上的MouseOver属性?

时间:2018-03-10 09:36:44

标签: c# .net wpf controls tabcontrol

所以我想禁用将鼠标移到控件上时发生的IsMouseOver效果。 这就是它的样子 https://i.imgur.com/P22YCLD.gifv

如何正确禁用它?

XAML

<Menu DockPanel.Dock="Top">
            <TabControl Background="DarkGray" BorderThickness="0" Height="150" Width="1273" Style="{DynamicResource TabControlStyle}">
                <TabControl.Resources>
                    <Style TargetType="TabItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="TabItem">
                                    <Border Name="Border" Margin="-2,0,0,-1" BorderThickness="0">
                                        <ContentPresenter x:Name="ContentSite"
                                                          VerticalAlignment="Center"
                                                          HorizontalAlignment="Center"
                                                          ContentSource="Header"
                                                          Margin="30,5"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="Border" Property="Background" Value="DarkGray" />
                                        </Trigger>
                                        <Trigger Property="IsSelected" Value="False">
                                            <Setter TargetName="Border" Property="Background" Value="#4f4f4f" />
                                            <Setter Property="Foreground" Value="White" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabControl.Resources>
                <TabItem Header="Import">
                    <Button Background="Transparent" BorderThickness="0" Margin="10,16,1184,14">
                        <Grid>
                            <Image Source="Icons/file.png"/>
                        </Grid>
                    </Button>
                </TabItem>

                <TabItem Header="Export" />
                <TabItem Header="Extra" />
            </TabControl>
        </Menu>

1 个答案:

答案 0 :(得分:0)

您可以在Menu中覆盖MenuItem的默认模板以删除默认样式

       <Menu.Resources>
            <Style TargetType="{x:Type MenuItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type MenuItem}">
                            <Border Background="{TemplateBinding Background}">
                                <ContentPresenter Content="{TemplateBinding Header}"/>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Menu.Resources>