自定义RoutedEvent作为EventTrigger

时间:2013-02-25 13:48:33

标签: c# wpf eventtrigger routedevents

我有自己的形状类

public sealed class MirrorTile : Shape

在本课程中我添加了活动

public static readonly RoutedEvent SelectedEnterEvent = EventManager.RegisterRoutedEvent("SelectedEnter", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MirrorTile));

public event RoutedEventHandler SelectedEnter
{
    add
    {
        this.AddHandler(SelectedEnterEvent, value);
    }

    remove
    {
        this.RemoveHandler(SelectedEnterEvent, value);
    }
}

并希望以这种方式使用它

<shapes:MirrorTile>
    <shapes:MirrorTile.Triggers>
        <EventTrigger RoutedEvent="SelectedEnter">
            <BeginStoryboard Storyboard="{StaticResource SelectShape}"/>
        </EventTrigger>
    </shapes:MirrorTile.Triggers>
</shapes:MirrorTile>

在starup之后我得到了异常: {"RoutedEventConverter cannot convert from System.String."}

我做错了什么,如何解决这个问题?

3 个答案:

答案 0 :(得分:7)

<EventTrigger RoutedEvent="shapes:MirrorTile.SelectedLeave">

命名空间也丢失了。

答案 1 :(得分:6)

您还必须提供类型:

<EventTrigger RoutedEvent="MirrorTile.SelectedEnter"></EventTrigger>

评论后编辑:

您是否尝试过在XAML声明中添加命名空间?

 xmlns:local="clr-namespace:YourNameSpace"

然后将其修复为:

 <EventTrigger RoutedEvent="local:MirrorTile.SelectedEnter"></EventTrigger>

答案 2 :(得分:2)

我认为您缺少定义事件的类型:

<EventTrigger RoutedEvent="MirrorTile.SelectedEnter">