Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF路由事件触发,但未由处理程序处理_C#_Wpf_Routed Events - Fatal编程技术网

C# WPF路由事件触发,但未由处理程序处理

C# WPF路由事件触发,但未由处理程序处理,c#,wpf,routed-events,C#,Wpf,Routed Events,我有以下事件: public static readonly RoutedEvent ItemMouseDownEvent = EventManager.RegisterRoutedEvent( "ItemMouseDown", RoutingStrategy.Bubble, typeof(ItemMouseDownEventHandler), typeof(BindableGrid)); public delegate void ItemMouseDownEventHandler(o

我有以下事件:

public static readonly RoutedEvent ItemMouseDownEvent = EventManager.RegisterRoutedEvent(
    "ItemMouseDown", RoutingStrategy.Bubble, typeof(ItemMouseDownEventHandler), typeof(BindableGrid));

public delegate void ItemMouseDownEventHandler(object sender, ItemMouseDownEventArgs e);

public class ItemMouseDownEventArgs : RoutedEventArgs
{
    public object Item { get; set; }
}

public event ItemMouseDownEventHandler ItemMouseDown
{
    add { AddHandler(ItemMouseDownEvent, value); }
    remove { RemoveHandler(ItemMouseDownEvent, value); }
}
我这样启动它(这段代码确实会被调用,我设置了一个断点):

我有一个使用该事件的XAML页面:

<local:BindableGrid x:Name="starSystemMap" ArraySource="{Binding SpaceObjectArray}" CellSize="64" BackgroundImage="/Images/Starfield.png" ItemMouseDown="starSystemMap_ItemMouseDown">
...
</local:BindableGrid>

现在,即使事件被引发,事件处理程序也不会被调用-为什么会这样?如何为自定义路由事件调用事件处理程序?

我在试图单击的
BindableGrid
上有额外的
BindableGrid
覆盖层;我必须在覆盖层上设置
ishitestvisible=“False”
,以便单击将“通过”到我想要单击的网格。

该事件,
ItemMouseDown
,如果注册一个处理程序,如
void h(objects s,EventArgs e)=>MsgBox.Show(s)我怀疑不是。也许您的事件声明不太正确。事件是用
event
关键字声明的,这个关键字很特殊;我将把事件声明添加到我的帖子中。添加和删除处理程序是否运行?这很奇怪;我在Add/RemoveHandler行上设置了一个断点,但它们没有被执行。我声明事件处理程序的XAML是否有问题?找到答案!=>需要在覆盖上设置IshitteVisible=“False”。
<local:BindableGrid x:Name="starSystemMap" ArraySource="{Binding SpaceObjectArray}" CellSize="64" BackgroundImage="/Images/Starfield.png" ItemMouseDown="starSystemMap_ItemMouseDown">
...
</local:BindableGrid>
private void starSystemMap_ItemMouseDown(object sender, BindableGrid.ItemMouseDownEventArgs e)
{
    switch (e.Item)
    {
        case null:
            MessageBox.Show("Space... the final frontier... is very, very empty...");
            break;
    }
}