zoukankan      html  css  js  c++  java
  • WPF CommandParameter的使用

    <Window x:Class="Wpf180706.Window5"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="Window5" Height="300" Width="300">
        <Window.CommandBindings>
            <CommandBinding Command="New" Executed="New_Execute" CanExecute="New_CanExecute"></CommandBinding>
        </Window.CommandBindings>
        <Grid>
            <StackPanel>
                <TextBox Name="txt"></TextBox>
                <Button Name="newTeacher" Command="New" CommandParameter="Teacher">NewTeacher</Button>
                <Button Name="newStudent"  Command="New" CommandParameter="Student">NewStudent</Button>

                <TextBlock Name="msg"></TextBlock>
            </StackPanel>
        </Grid>

    </Window>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;


    namespace Wpf180706
    {
        /// <summary>
        /// Interaction logic for Window5.xaml
        /// </summary>
        public partial class Window5 : Window
        {
            public Window5()
            {
                InitializeComponent();
            }


            private void New_Execute(object sender, ExecutedRoutedEventArgs e)
            {
                msg.Text = e.Parameter.ToString();
            }


            private void New_CanExecute(object sender, CanExecuteRoutedEventArgs e)
            {
                if (string.IsNullOrEmpty(txt.Text))
                {
                    e.CanExecute = false;
                }
                else
                {
                    e.CanExecute = true;
                }
            }
        }
    }

  • 相关阅读:
    [题解] [NOIP2008] 双栈排序——关系的冲突至图论解法
    [搬运] [贪心]NOIP2011 观光公交
    [总结] 最短路径数问题
    [持续更新]一些zyys的题的集合
    [教程]Ubuntu下完整配置自动壁纸切换
    在NOILINUX下的简易VIM配置
    [模板]ST表浅析
    21、Android--RecyclerView
    20、Android--GridView
    19、Android--ListView
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434612.html
Copyright © 2011-2022 走看看