欢迎来到 IT实训基地-南通科迅教育
咨询电话:0513-81107100
WPF(命令参数)
2017/1/11
科迅教育
328
南通哪个Web前端培训机构价格较低

[html] 
<Window x:Class="TestOfCommandParameter.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="MainWindow" Height="350" Width="525" 
        Background="LightBlue" WindowStyle="ToolWindow"> 
    <Grid Margin="6"> 
        <Grid.RowDefinitions > 
            <RowDefinition Height="24" /> 
            <RowDefinition Height="4" /> 
            <RowDefinition Height="24" /> 
            <RowDefinition Height="4" /> 
            <RowDefinition Height="24" /> 
            <RowDefinition Height="4" /> 
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
         
        <TextBlock Text="Name:" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="0" /> 
        <TextBox x:Name="newTextBox" Margin="60,0,0,0" 
                 Grid.Row="0" /> 
        <Button Content="New Teacher" 
                Command="New"  
                CommandParameter="Teacher" 
                Grid.Row="2" /> 
        <Button Content="New Student" 
                Command="New"  
                CommandParameter="Student" 
                Grid.Row="4" /> 
        <ListBox x:Name="listBoxNewItems"  
                 Grid.Row="6" /> 
    </Grid> 
     
    <Window.CommandBindings> 
        <CommandBinding Command="New" CanExecute="New_CanExecute" 
                        Executed="New_Executed" /> 
    </Window.CommandBindings> 
</Window> 

<Window x:Class="TestOfCommandParameter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        Background="LightBlue" WindowStyle="ToolWindow">
    <Grid Margin="6">
        <Grid.RowDefinitions >
            <RowDefinition Height="24" />
            <RowDefinition Height="4" />
            <RowDefinition Height="24" />
            <RowDefinition Height="4" />
            <RowDefinition Height="24" />
            <RowDefinition Height="4" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
       
        <TextBlock Text="Name:" VerticalAlignment="Center" HorizontalAlignment="Left" Grid.Row="0" />
        <TextBox x:Name="newTextBox" Margin="60,0,0,0"
                 Grid.Row="0" />
        <Button Content="New Teacher"
                Command="New"
                CommandParameter="Teacher"
                Grid.Row="2" />
        <Button Content="New Student"
                Command="New"
                CommandParameter="Student"
                Grid.Row="4" />
        <ListBox x:Name="listBoxNewItems"
                 Grid.Row="6" />
    </Grid>
   
    <Window.CommandBindings>
        <CommandBinding Command="New" CanExecute="New_CanExecute"
                        Executed="New_Executed" />
    </Window.CommandBindings>
</Window>
[csharp]
using System.Windows; 
 
namespace TestOfCommandParameter 

    /// <summary>  
    /// Interaction logic for MainWindow.xaml  
    /// </summary>  
    public partial class MainWindow : Window 
    { 
        public MainWindow() 
        { 
            InitializeComponent(); 
        } 
 
        private void New_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) 
        { 
            if (string.IsNullOrEmpty(this.newTextBox.Text)) 
            { 
                e.CanExecute = false; 
            } else 
            { 
                e.CanExecute = true; 
            } 
        } 
 
        private void New_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) 
        { 
            string name = this.newTextBox.Text; 
            if (e.Parameter.ToString()=="Teacher") 
            { 
                this.listBoxNewItems.Items.Add(string.Format("New Teacher:{0},学而不厌,诲人不倦。", name)); 
            } 
 
            if (e.Parameter.ToString() == "Student") 
            { 
                this.listBoxNewItems.Items.Add(string.Format("New Student:{0},好好学习,天天向上。", name)); 
            } 
        } 
    } 

using System.Windows;

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

        private void New_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.newTextBox.Text))
            {
                e.CanExecute = false;
            } else
            {
                e.CanExecute = true;
            }
        }

        private void New_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            string name = this.newTextBox.Text;
            if (e.Parameter.ToString()=="Teacher")
            {
                this.listBoxNewItems.Items.Add(string.Format("New Teacher:{0},学而不厌,诲人不倦。", name));
            }

            if (e.Parameter.ToString() == "Student")
            {
                this.listBoxNewItems.Items.Add(string.Format("New Student:{0},好好学习,天天向上。", name));
            }
        }
    }
}

77
关闭
先学习,后交费申请表
每期5位名额
在线咨询
免费电话
QQ联系
先学习,后交费
TOP
您好,您想咨询哪门课程呢?
关于我们
机构简介
官方资讯
地理位置
联系我们
0513-91107100
周一至周六     8:30-21:00
微信扫我送教程
手机端访问
南通科迅教育信息咨询有限公司     苏ICP备15009282号     联系地址:江苏省南通市人民中路23-6号新亚大厦三楼             法律顾问:江苏瑞慈律师事务所     Copyright 2008-