码迷,mamicode.com
首页 > Windows程序 > 详细

WPF Command

时间:2017-06-13 14:41:20      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:oca   aml   static   用法   err   lte   frame   framework   type   

使用CustomControl时绑定Command用法

C# Part

 1 public static RoutedUICommand ClearCommand { get; private set; }
 2 
 3 static CustomControl()
 4 {
 5     DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl), new FrameworkPropertyMetadata(typeof(CustomControl)));
 6     CustomControl.ClearCommand = new RoutedUICommand();
 7     CommandBinding ClearCommandBinding=new CommandBinding(CustomControl.ClearCommand,CustomControl.ClearText);
 8     CommandManager.RegisterClassCommandBinding(typeof(CustomControl), ClearCommandBinding);
 9 }
10 
11 private static void ClearText(object sender, ExecutedRoutedEventArgs e)
12 {
13     ...
14 }

XAML Part

1 <Style TargetType="local:CustomControl">
2     <Setter Property="Template">
3         <Setter.Value>
4             <ControlTemplate TargetType="local:LabelEditCtrl">
5                 <Button Command="{x:Static local:CustomControl.ClearCommand}"/>
6             </ControlTemplate>
7         </Setter.Value>
8     </Setter>
9 </Style>

 

WPF Command

标签:oca   aml   static   用法   err   lte   frame   framework   type   

原文地址:http://www.cnblogs.com/RabbitCC/p/7000458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!