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

代码地址:

相关推荐
疯狂成瘾者3 分钟前
Java 常用工具包 java.util
java·开发语言·windows
无为之士5 分钟前
Windows 批量打印 PDF 工具分享:支持文件夹、指定文件、当天文件、预览列表
windows·powershell
rhythm-ring1 小时前
TortoiseSVN 配置 Beyond Compare 注意事项
windows
凡人叶枫1 小时前
Effective C++ 条款38:通过复合塑模出 has-a 或 \“根据某物实现出\
linux·开发语言·c++·windows
caimouse2 小时前
Reactos 第 9 章 设备驱动 — 9.14 IRP请求的完成与返回
windows
虾壳云官方2 小时前
openclaw 一键安装教程(2026年6月15最新)
运维·人工智能·windows·自动化·openclaw
qq_338432373 小时前
VSCode Remote-SSH 远程 Windows Server 卡死的排查与解决
windows·vscode·ssh
大佐不会说日语~3 小时前
在 Windows 本地用 Docker 部署向量模型(bge-m3)
windows·docker·容器·llm·ollama
凡人叶枫4 小时前
Effective C++ 条款37:绝不重新定义继承而来的缺省参数值
linux·c++·windows
ccino .4 小时前
【电脑的睡眠和休眠区别】
windows