小编lav*_*ava的帖子

WPF FrameworkElement未接收鼠标输入

试图让OnMouse事件出现在孩子身上FrameworkElement.父元素是Panel(并且Background属性不是Null).

class MyFrameworkElement : FrameworkElement
{
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        // Trying to get here!
        base.OnMouseDown(e);
    }
}

public class MyPanel : Panel
{
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        // This is OK
        base.OnMouseDown(e);
    }
}
Run Code Online (Sandbox Code Playgroud)

OnMouse永远不会被调用,事件总是未被处理,Snoop告诉我,路由事件似乎只能到达Panel元素.

<Window 
  x:Class="WpfApplication5.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:l="clr-namespace:WpfApplication5"
  Title="Window1" Height="300" Width="300">
  <Border x:Name="myBorder" Background="Red">
    <l:MyPanel x:Name="myPanel" Background="Transparent">
      <l:MyFrameworkElement x:Name="myFE"/>
    </l:MyPanel>
  </Border>
</Window>
Run Code Online (Sandbox Code Playgroud)

文档说FrameworkElement处理输入,但为什么不在这种情况下?

wpf routedevent mouseevent frameworkelement

10
推荐指数
2
解决办法
2019
查看次数

标签 统计

frameworkelement ×1

mouseevent ×1

routedevent ×1

wpf ×1