首页 > Windows开发 > 详细

WPF Command

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

使用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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!