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

代码地址:

相关推荐
LSL666_6 小时前
MybatisPlus条件构造器(下)
java·开发语言·windows·mybatisplus
手揽回忆怎么睡7 小时前
win11显卡NVIDIA GeForce GTX 1660的ComfyUI_windows_portable_nvidia_cu126的节点包安装不上
windows
AxureMost8 小时前
Windows系统调校 20260324 系统优化工具
windows
NGBQ121388 小时前
ZBrush-2026.0.0-x64-CN-Portable.exe 全解析:Windows 端专业数字雕刻与绘画软件深度指南
windows·数字雕刻·zbrush
牧天白衣.8 小时前
01-集合高级
windows
残雪飞扬10 小时前
Ubuntu上安装 WinBoat(让linux上运行windows软件)
linux·windows·ubuntu
图灵机z10 小时前
【操作系统】四、进程管理
linux·服务器·网络·windows·macos·centos·risc-v
soldierluo11 小时前
openclaw接入企业微信
服务器·人工智能·windows·企业微信
西柚00111 小时前
Windows 安装 MySQL5.7.30正常情况与异常情况
windows
晨曦蜗牛11 小时前
Windows 上 Claude Code 报错 “requires git-bash“ 的完整解决方案
windows·git·bash