region - 用于绑定ViewModel部分 -

    public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
} // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CommandProperty =
DependencyProperty.Register("Command", typeof(ICommand), typeof(MyUserControl), new PropertyMetadata(default(ICommand))); public object CommandParameter
{
get { return (object)GetValue(CommandParameterProperty); }
set { SetValue(CommandParameterProperty, value); }
} // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.Register("CommandParameter", typeof(object), typeof(MyUserControl), new PropertyMetadata(default(object))); public IInputElement CommandTarget { get; set; } #endregion

region 用于Xaml触发路由事件部分

    //声明和注册路由事件
public static readonly RoutedEvent MyEventRoutedEvent =
EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(MyUserControl));
//CLR事件包装
public event RoutedEventHandler MyEvent
{
add { this.AddHandler(MyEventRoutedEvent, value); }
remove { this.RemoveHandler(MyEventRoutedEvent, value); }
} //激发路由事件,借用Click事件的激发方法 protected void OnMyEvent()
{
RoutedEventArgs args = new RoutedEventArgs(MyEventRoutedEvent, this);
this.RaiseEvent(args);
} #endregion

///

内部触发的路由事件和自定义命令方法

private void Button_Click(object sender, RoutedEventArgs e)

{

//命令作用于命令目标

if (this.Command != null)

{

this.Command.Execute(CommandParameter);

            this.OnMyEvent();
}
}

<local:MyUserControl Grid.Row="1" Command="{Binding RelayCommand}" CommandParameter="Sumit">

local:MyUserControl.Triggers















</local:MyUserControl.Triggers>

</local:MyUserControl>

最新文章

  1. 【linux】scp命令
  2. C#调用exe文件,IIS发布后无法掉用本地exe程序的解决方法
  3. mysql分表和表分区详解
  4. LeetCode —— Invert Binary Tree
  5. Geolocation
  6. bxSlider 在网页里添加幻灯片效果
  7. Java Collections的排序之二
  8. 生日蛋糕 (codevs 1710) 题解
  9. 修改ptrace_scope
  10. iOS 使用FMDB SQLCipher给数据库加密
  11. mkimage的-a 和 –c参数和内核引导
  12. [Design Pattern] Iterator Pattern 简单案例
  13. chroot jail
  14. [Spark內核] 第41课:Checkpoint彻底解密:Checkpoint的运行原理和源码实现彻底详解
  15. USACO 2017 January Platinum
  16. IntelliJ IDEA 常用插件
  17. 【CentOS7.0】虚拟机如何实现扩展存储空间
  18. typescript 与 js 开发 react 的区别
  19. 数据库SQL语句性能优化
  20. python 获取有关访问者的浏览器的 细节

热门文章

  1. markdown中如何设置字体为红色?
  2. Angular中的routerLink 跳转页面和默认路由
  3. ISO/IEC 9899:2011 条款6.4.8——预处理数字
  4. Qt编写自定义控件56-波浪曲线
  5. 学习 TTreeView [16] - 给 TTreeView 添加复选框 (回复 &quot;丁永其&quot; 的问题)
  6. node.js使用superagent实现模拟登陆功能(包含下载验证码功能)
  7. 【Leetcode_easy】661. Image Smoother
  8. 【leetcode_easy】598. Range Addition II
  9. Direct2D 学习笔记 前言
  10. 最新 蚂蚁金服java校招面经 (含整理过的面试题大全)