zoukankan      html  css  js  c++  java
  • WPF 中的 Command 命令

    <Window x:Class="CommandDemo.MainWindow"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

            xmlns:local="clr-namespace:CommandDemo"

            mc:Ignorable="d"

            Title="MainWindow" Height="450" Width="800">

        <Grid>

            <StackPanel x:Name="stackpanel" >

                <Button x:Name="button1"  Content="send command"></Button>

                <TextBox x:Name="textboxA" Margin="5,0" Height="100"></TextBox>

                <TextBox x:Name="textboxB" Margin="5,0" Height="100"></TextBox>

            </StackPanel>

        </Grid>

    </Window>

    C# 代码

     public partial class MainWindow : Window

        {

            public MainWindow()

            {

                InitializeComponent();

                this.InitializeCommand();

            }

            private RoutedCommand ClearCmd = new RoutedCommand("clear", typeof(MainWindow));

            private void InitializeCommand()

            {

                this.ClearCmd.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Alt));

                this.button1.Command = this.ClearCmd;

                this.button1.CommandTarget = this.textboxA;

                CommandBinding cb = new CommandBinding();

                cb.Command = this.ClearCmd;

                cb.CanExecute += new CanExecuteRoutedEventHandler(cb_CanExecute);

                cb.Executed += new ExecutedRoutedEventHandler(cb_Executed);

                this.stackpanel.CommandBindings.Add(cb);

            }

            private void cb_Executed(object sender, ExecutedRoutedEventArgs e)

            {

                this.textboxA.Clear();

            }

            private void cb_CanExecute(object sender, CanExecuteRoutedEventArgs e)

            {

                e.CanExecute = true;

            }

        }

  • 相关阅读:
    mysql 自定义排序
    arcgis 好人
    eclipse启动tomcat,提示三个端口均被占用
    oracle 查看表空间创建日期
    navacat 链接oracle oci invalid handle
    java +mysql 递归排序/* START WITH aa.parentid IN ( 10000, 20000, 30000, 40000, 50000, 60000, 70000 ) connect BY prior aa.id = aa.parentid ORDER siblings BY aa.id ASC*/ to
    Double 转 BigDecimal
    mysql 死锁 Waiting for stored function metadata lock
    Graphtree--zabbix增强功能(一屏展示所有内容)
    zabbix 分布式监控(proxy)源码安装
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14531762.html
Copyright © 2011-2022 走看看