wpf 自定义 RoutedEvent 作为 EventTrigger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15068471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom RoutedEvent as EventTrigger
提问by Christian
I have my own shape class
我有自己的形状课
public sealed class MirrorTile : Shape
and in this class I added the event
在这门课中我添加了事件
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);
}
}
and want to use it in this way
并想以这种方式使用它
<shapes:MirrorTile>
<shapes:MirrorTile.Triggers>
<EventTrigger RoutedEvent="SelectedEnter">
<BeginStoryboard Storyboard="{StaticResource SelectShape}"/>
</EventTrigger>
</shapes:MirrorTile.Triggers>
</shapes:MirrorTile>
After starup I get the exception:
{"RoutedEventConverter cannot convert from System.String."}
启动后,我得到异常:
{"RoutedEventConverter cannot convert from System.String."}
What I'm doing wrong and how can I fix this problem?
我做错了什么,我该如何解决这个问题?
回答by Christian
<EventTrigger RoutedEvent="shapes:MirrorTile.SelectedLeave">
<EventTrigger RoutedEvent="shapes:MirrorTile.SelectedLeave">
the namespace was missing also.
命名空间也丢失了。
回答by l46kok
You have to provide the type as well:
您还必须提供类型:
<EventTrigger RoutedEvent="MirrorTile.SelectedEnter"></EventTrigger>
Edit upon comment:
编辑评论:
Have you tried adding a namespace to your XAML declaration?
您是否尝试在 XAML 声明中添加命名空间?
xmlns:local="clr-namespace:YourNameSpace"
Then fix this to:
然后将其修复为:
<EventTrigger RoutedEvent="local:MirrorTile.SelectedEnter"></EventTrigger>
回答by satnhak
I think you are missing the type that defines your event:
我认为您缺少定义事件的类型:
<EventTrigger RoutedEvent="MirrorTile.SelectedEnter">

