gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:33:37 25 4
gpt4 key购买 nike

我的应用程序有一种磁贴系统。请看下面的代码:

<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>

如您所见,我有主容器 ([icode]WrapPanel[/icode]),然后我有多个 [icode]DockPanel[/icode] 构成图 block 本身。

出于某种原因,当我将鼠标悬停在 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>

有什么想法吗?

最佳答案

尝试将 DockPanel 的背景设置为透明。当 background 为 null 时,WPF 不会将其包含在 hit test 中.

关于WPF DockPanel IsMouseOver 仅在将鼠标悬停在子控件上时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26101128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com