當我在Rectangle上移動標籤時,我想要矩形觸發一個mouseEnter
事件,因爲Label與Rectangle重疊,所以它不起作用。我嘗試了isHitTestVisible = false
,但後來我無法移動標籤。有沒有辦法做到這一點?WPF:在另一個UIElement重疊的UIElement上觸發mouseenter
回答
我使用了邊框,因爲如果我沒有記錯的話,這是它可以完成的唯一方法。
WINDOW.RESOURCES
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFE6E6E6"/>
</Trigger>
</Style.Triggers>
</Style>
GRID
<Border BorderBrush="#FF000000" BorderThickness="0,0,3,3" Grid.Row="0" Grid.Column="0">
<Image Name="x0y0" Source="/Tictactoe;component/image/null-black.png"/>
</Border>
我希望我抓住了正確的東西給你。 :p
這是你在找什麼? `
<Grid>
<Rectangle x:Name="rect" Fill="{Binding ElementName=label, Path=Background}" />
<TextBlock x:Name="label" Text="Hover over me" >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="100" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
`
不,這不是我想要做的。我想我的問題還不夠清楚,我編輯了它。 –
我這是怎麼實現這種效果與我DataGridRow對象。也許它可以幫助。
<EventTrigger RoutedEvent="DataGridRow.DragEnter">
<BeginStoryboard x:Name="DragEnterStoryboard">
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="Background.Color"
To="{StaticResource PartEntityDragEnterBackgroundColor}"
Duration="0:0:0.25"/>
<ColorAnimation
Storyboard.TargetProperty="Foreground.Color"
To="{StaticResource PartEntityDragEnterForegroundColor}"
Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
這也沒有奏效。不知何故,當鼠標移動UIElement時,mouseenter事件不會被觸發。 –
你確定你在使用DragEnter而不是MouseEnter嗎? – Jace
我嘗試了兩種方法,但仍無法使用 –
- 1. WPF樣式觸發國外的UIElement
- 2. 如何重置WPF UIElement?
- 3. WPF在UIElement上檢測多個HitTest
- 4. 在FlowDocument中選擇一個WPF UIElement
- 5. C#每當另一個UIElement通過他時刪除UIElement
- 6. 後訪問的UIElement在WPF
- 7. 從示例中創建一個wpf UIElement
- 8. 基於另一個類的UiElement
- 9. WPF樣式使用的UIElement
- 10. WPF/Silverlight中的UIElement vs FrameworkElement
- 11. WPF中的幾何HitTest UIElement
- 12. 是否有可能將WPF WebBrowser與其他UIElement重疊?
- 13. 獲取WPF UIElement的左上角座標
- 14. WPF故事板可以應用於UIElement從UIElement(在代碼中)中發現嗎?
- 15. WPF UIElement刷新錯誤?
- 16. WPF CLR類型到UIElement
- 17. WPF FrameworkElement父和移動UIElement
- 18. 在重疊div上觸發多個mouseenter/mouseleave事件
- 19. 在ASP.NET中生成WPF UIElement的位圖
- 20. WPF - 確定是否鼠標在的UIElement
- 21. 在wpf中查找uielement的中心
- 22. 如何重置UIElement上的DesiredSize
- 23. 的Silverlight 3DROTATE +上的UIElement將
- 24. 在WPF中使用AddLogicalChild,AddVisualChild添加UIElement
- 25. 如何在WPF中找到UIElement?
- 26. 更改的UIElement
- 27. JQuery mouseenter在重疊div上多次觸發
- 28. wpf UIElement的自定義事件
- 29. 使用UIElement作爲WPF中的剪輯
- 30. 圖像位於的UIElement不顯示[WPF]
不幸的是,當我懸停在上面的標籤上時,它不工作 –
對不起。我認爲這可能是有用的。 – 2016-03-27 22:48:42