WPF DockPanel IsMouseOver仅在子控件被鼠标悬停时触发

Mar*_*all 2 wpf xaml

我的应用程序有一种瓷砖系统.请参阅以下代码:

<WrapPanel Grid.Column="0" Grid.Row="1">
    <DockPanel Style="{StaticResource Panel}">
        <Label Content="Upload"/>
        <Image Width="40">
            <Image.Source>
                <BitmapImage DecodePixelWidth="40" UriSource="images/download.png" />
            </Image.Source>
        </Image>
    </DockPanel>
</WrapPanel>
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我有了主容器([icode] WrapPanel [/ icode]),然后我有了多个[icode] DockPanel [/ icode],它们构成了tile本身.

出于某些原因,当我将鼠标悬停在DockPanel上时,IsMouseOver触发器不会触发,但是当我将鼠标悬停在它的任何一个子节点上时它会触发.触发后,它会一直触发,直到我的鼠标离开DockPanel.

这是风格:

<Style x:Key="Panel" TargetType="DockPanel">
    <Setter Property="Margin" Value="4" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Height" Value="118" />
    <Setter Property="Width" Value="118" />
    <Setter Property="LastChildFill" Value="True" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="#FF212121" />
        </Trigger>
    </Style.Triggers>
    <Style.Resources>
        <Style TargetType="Label">
            <Setter Property="Foreground" Value="White" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Bottom" />
            <Setter Property="Margin" Value="3" />
            <Setter Property="DockPanel.Dock" Value="Bottom" />
        </Style>
    </Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

mt_*_*erg 9

尝试将DockPanel的背景设置为透明.当background为null时,WPF将不会在命中测试中包含它.