WPF - TabItem MouseOver not working as intended

后端 未结 2 653
-上瘾入骨i
-上瘾入骨i 2021-01-19 14:56

I have an issue with the IsMouveOver trigger with a TabItem Element.

When the mouse cursor is on a TabItem, its background color changes, which is what I want => It

相关标签:
2条回答
  • 2021-01-19 15:32

    It does not work because Border as container takes all events, and MouseOver is not exception. If you want to ignore MouseOver event for some part (your inner part of the item) then just put inner item on top of wider item.

    You can add Grid control beneath inner part and bind Trigger to its MouseOver event.

        <Border Margin="2" Name="TabBorder" CornerRadius="6" BorderBrush="Transparent" Background="Transparent" 
    BorderThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <Grid>
        <Grid x:Name="gridMouseOver"/>
        <StackPanel Margin="12" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Rectangle Width="25" Height="25" Fill="Blue" HorizontalAlignment="Left" Margin="00,0,0,0"></Rectangle>
                <ContentPresenter ContentSource="Header" VerticalAlignment="Center" 
                        HorizontalAlignment="Stretch" Margin="10,0,0,0"></ContentPresenter>
            </StackPanel>
    </Grid>
    </Border>
    <ControlTemplate.Triggers>
    <Trigger Property="IsSelected" Value="True">
        <Setter Property="Panel.ZIndex" Value="100" />
        <Setter TargetName="TabBorder" Property="Background" Value="#FFDFDFDF" />
        <Setter TargetName="TabBorder" Property="BorderThickness" Value="2" />
        <Setter TargetName="TabBorder" Property="BorderBrush" Value="{DynamicResource WindowTitleColorBrush}"/>
    </Trigger>
    <Trigger Property="IsEnabled" Value="False">
        <Setter TargetName="TabBorder" Property="Background" Value="DarkRed" />
        <Setter TargetName="TabBorder" Property="BorderBrush" Value="Black" />
        <Setter Property="Foreground" Value="DarkGray" />
    </Trigger>
    <Trigger SourceName="gridMouseOver" Property="IsMouseOver" Value="True">
        <Setter TargetName="TabBorder" Property="Background" Value="{DynamicResource WindowTitleColorBrush}"/>
    </Trigger>
    </ControlTemplate.Triggers>
    
    0 讨论(0)
  • 2021-01-19 15:53

    bit of an old question but this has been troubling me all day....

    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
        <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false"/>
        <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" Value="Top"/>
    </MultiDataTrigger.Conditions>
    

    This solved it for me

    ignores the mouse over for the active tab

    Hope this helps any one who has this problem

    0 讨论(0)
提交回复
热议问题