WPF基础入门-Class5-WPF命令

WPF基础入门

Class5-WPF命令

1、xaml编写一个button,Command绑定一个命令

xml 复制代码
<Grid>
        <Button
            Width="100"
            Height="40" Command="{Binding ShowCommand}"></Button>
</Grid>

2、编写一个model.cs

cs 复制代码
namespace WPF_Learn.Model
{
    class model_csdn
    {
        public model_csdn()
        {
            ShowCommand = new MyCommamd(show);
        }
		//注册命令,名字和xaml中一致
        public MyCommamd ShowCommand { get; set; }  

        public void show()
        {
            MessageBox.Show("Show Message");
        }
    }
}

3、页面的cs文件绑定数据

cs 复制代码
public WPF_Form()
        {
            InitializeComponent();
            // 找到数据源 数据上下文
            this.DataContext = new WPF_Learn.Model.model_csdn();
        }

点击页面按钮:

相关推荐
极客智造3 小时前
深入解析 ReactiveUI:WPF 响应式 MVVM 开发的 “终极方案”
wpf
Macbethad2 天前
使用WPF编写一个多维度伺服系统的程序
大数据·hadoop·wpf
lingxiao168882 天前
WPF Prism框架应用
c#·wpf·prism
Macbethad2 天前
使用WPF编写一个Ethercat主站的程序
wpf
难搞靓仔2 天前
WPF 弹出窗体Popup
wpf·popup
Macbethad2 天前
使用WPF编写一个MODBUSTCP通信的程序
wpf
unicrom_深圳市由你创科技2 天前
Avalonia.WPF 跨平台图表的使用
wpf
-大头.3 天前
深入解析ZooKeeper核心机制
分布式·zookeeper·wpf
Macbethad3 天前
使用WPF编写一个RS232主站程序
wpf
Macbethad3 天前
使用WPF编写一个485通信主站程序
wpf