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();
        }

点击页面按钮:

相关推荐
秋の本名4 小时前
第一章 鸿蒙生态架构与开发理念
华为·wpf·harmonyos
Bofu-7 小时前
【音频测试】03-WPF 实现声道自动验证 + Whisper 语音识别录音检测
c#·whisper·wpf·音视频·音频测试·naudio 声道控制
秋の本名7 小时前
DevEco Studio 版本演进揭秘:从3.0到5.0的分布式开发能力飞跃与智能体验革新
wpf·鸿蒙系统
heimeiyingwang3 天前
【架构实战】状态机架构:订单/工单状态流转设计
观察者模式·架构·wpf
KmSH8umpK4 天前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第三篇
redis·分布式·wpf
KmSH8umpK4 天前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案
redis·分布式·wpf
武藤一雄4 天前
WPF:MessageBox系统消息框
前端·microsoft·c#·.net·wpf
武藤一雄4 天前
WPF进阶:万字详解WPF如何性能优化
windows·性能优化·c#·.net·wpf·.netcore·鲁棒性
wangnaisheng4 天前
【WPF】路由事件详细使用
wpf