WPF使用Prism实现简单订餐系统

新建wpf项目,nuget引入Prism.DryIoc,MaterialDesignThemes

引入后,修改App.xaml 前台引入 xmlns:prism="http://prismlibrary.com/"和prism:PrismApplication App.xaml.cs

App.xaml.cs继承PrismApplication,重写CreateShell和RegisterTypes

cs 复制代码
   protected override Window CreateShell()
   {
       return Container.Resolve<MainWindow>();
  


   }

   protected override void RegisterTypes(IContainerRegistry containerRegistry)
   {

   }

MainWindowViewModel继承BindableBase,实现mvvm

上面步骤,同样可以通过新建prism 项目,自动引入引入了prism

在model中新建属性,实现属性自动通知功能

cs 复制代码
    private double _total;

    public double Total
    {
        get { return _total; }
        set
        {
            _total = value;
            RaisePropertyChanged();
        }
    }

前台绑定

cs 复制代码
 <TextBox VerticalAlignment="Center" x:Name="Total" Text="{Binding Total}"  Width="70" Margin="4 0 0 0" TextAlignment="Center" BorderThickness="0 0 0 2"></TextBox>

新建Command

public DelegateCommand SelCommand { get; set; }

在构造函数中,绑定委托方法

SelCommand = new DelegateCommand(()=> {

SelectDish();

DispAllSelect();

});

如果方法带有参数,可以使用DelegateCommand<T>泛型声明

前台绑定控件Command属性调用

<CheckBox IsChecked="{Binding IsSelected,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Command="{Binding DataContext.SelCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" ></CheckBox>

最后实现简单的Order系统

代码地址:

相关推荐
2601_9623649712 小时前
Windows Hello VS 传统密码:身份认证安全层级全面对比分析
windows·安全·电脑
Imagine Miracle16 小时前
【WSL】让WSL2后台持久运行不自动关闭的解决方案
linux·windows·wsl
啦啦啦~~~22216 小时前
经典小游X,免费刺激,可离线使用!
windows·游戏·开源软件
月走乂山18 小时前
Windows提示调制解调器报错、同交换机其他电脑正常、远程能连但浏览器打不开——本机DNS配置问题排查
windows·dns·故障排查·网络故障·网络诊断
衔烛之龙120 小时前
Windows x64 构建 liboqs-java教程
java·windows·python
阿豪只会阿巴1 天前
两小时快速入门 FastAPI--第二回
windows·python·fastapi
印度神油92 天前
Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
windows·python·ci/cd
2601_963771372 天前
Hardening Enterprise WordPress Sites Against REST API Leaks and Bad Headers
前端·windows·word·php
不要小看我们之间的羁绊啊2 天前
【windows】cc + cc switch + headroom
windows
找死的豆腐2 天前
基于.NET的Windows窗体编程之WinForms图像控件
windows·.net