admin管理员组文章数量:1589758
本例依赖文章 https://blog.csdn/Vblegend_2013/article/details/81634020
用户控件代码
/// <summary>
/// 声明路由事件
/// 参数:要注册的路由事件名称,路由事件的路由策略,事件处理程序的委托类型(可自定义),路由事件的所有者类类型
/// </summary>
public static readonly RoutedEvent OnToolTipShowEvent = EventManager.RegisterRoutedEvent("OnToolTipShow", RoutingStrategy.Bubble, typeof(MyEventArgs), typeof(MyUserControl));
/// <summary>
/// 处理各种路由事件的方法
/// </summary>
public event RoutedEventHandler OnToolTipShow
{
//将路由事件添加路由事件处理程序
add { AddHandler(OnToolTipShowEvent, value,false); }
//从路由事件处理程序中移除路由事件
remove { RemoveHandler(OnToolTipShowEvent, value); }
}
MyEventArgs 必须继承 RoutedEventArgs
public class MyEventArgs: RoutedEventArgs
{
...你的事件参数
}
用户控件中触发事件
var param = new MyEventArgs();
param.RoutedEvent = OnToolTipShowEvent;
param.Source = this;
this.RaiseEvent(param);
WPF绑定
<MyUserControl>
<i:Interaction.Triggers>
<i:EventTrigger EventName="OnToolTipShow">
<cmd:EventCommand Command="{Binding OnToolTipShow}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</MyUserControl>
MVVM
public IDefaultCommand OnToolTipShow
{
get
{
return new CallCommand<MyEventArgs>((s, e) =>
{
}, (s, o) => { return true; });
}
}
本文标签: MvvmWPFUserControlTriggersInteraction
版权声明:本文标题:WPF MVVM UserControl 的 i:Interaction.Triggers 应用 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728077093a1144621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论