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

点击页面按钮:

相关推荐
Scout-leaf7 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
柒.梧.9 天前
基于SpringBoot+JWT 实现Token登录认证与登录人信息查询
wpf
十月南城12 天前
Flink实时计算心智模型——流、窗口、水位线、状态与Checkpoint的协作
大数据·flink·wpf
听麟15 天前
HarmonyOS 6.0+ 跨端会议助手APP开发实战:多设备接续与智能纪要全流程落地
分布式·深度学习·华为·区块链·wpf·harmonyos
@hdd15 天前
Kubernetes 可观测性:Prometheus 监控、日志采集与告警
云原生·kubernetes·wpf·prometheus
zls36536515 天前
C# WPF canvas中绘制缺陷分布map
开发语言·c#·wpf
专注VB编程开发20年15 天前
c#Redis扣款锁的设计,多用户,多台电脑操作
wpf
闲人编程16 天前
定时任务与周期性调度
分布式·python·wpf·调度·cron·定时人物·周期性
zls36536516 天前
C# WPF canvas中绘制缺陷分布map并实现缩放
开发语言·c#·wpf
数据知道17 天前
PostgreSQL:Citus 分布式拓展,水平分片,支持海量数据与高并发
分布式·postgresql·wpf