试图获取出现在子女FrameworkElement
中的OnMouse事件。父元素是Panel
(并且Background
属性不为空)。WPF FrameworkElement未接收鼠标输入
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);
}
}
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>
Docs说FrameworkElement
处理输入,但为什么不在这种情况下?
感谢您的答复。我一直在玩弄一点点,并设法让我需要通过添加以下到FrameworkElement的行为: 保护覆盖无效的OnRender(的DrawingContext的DrawingContext) { 尺寸renderSize = this.RenderSize; Rect rect = new Rect(renderSize); Pen pen = new Pen(Brushes.Transparent,0.0); 012Context.DrawRectangle(Brushes.Transparent,pen,rect); } 也许FrameworkElement的大小为零,除非添加了一些东西? – lava 2010-07-16 23:11:10