首页 > 代码库 > WPF Command
WPF Command
使用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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。