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系统

代码地址:

相关推荐
heimeiyingwang1 小时前
【架构实战】Event Sourcing事件溯源详解
windows·架构
少控科技2 小时前
小数典 - V1.0.0.1
windows·c#
遇见火星2 小时前
Firewalld 防火墙实战指南 + TCPWrapper 七层访问控制
开发语言·windows·python
eastyuxiao3 小时前
MMM 工具一键去水印+检测 批处理脚本(Windows/Mac 双版本)
人工智能·windows·macos·ai音乐去水印
Ching·3 小时前
MAC mini上面安装虚拟机windows11的安装详细过程及其问题解决
windows·macos·wmware fusion
Controller-Inversion3 小时前
207. 课程表
windows
longerxin202014 小时前
卸载 CCleaner 失败?用 Revo Uninstaller 彻底清干净(附官方下载 + 详细步骤)
windows
AC赳赳老秦17 小时前
OpenClaw多平台部署:Windows+Linux跨系统协同,实现全场景覆盖
linux·服务器·前端·网络·windows·deepseek·openclaw
feVA LTYR19 小时前
Windows上安装Go并配置环境变量(图文步骤)
开发语言·windows·golang
加号319 小时前
Windows10 免密码/空密码实现远程桌面连接:完整配置指南
windows