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

代码地址:

相关推荐
Qiuner9 小时前
Pico 重塑Agent时代人与数据交互方式
windows·docker·ai·架构
FL16238631299 小时前
Windows x64 系统安装 ChromeDriver
windows
百事牛科技11 小时前
两种方法锁定 PDF,拒绝内容被随意篡改
windows·pdf
云樱梦海15 小时前
OpenClaw官方:OpenClaw Windows Node 实战(1.5K ★ 开源推荐)
windows·开源·github·openclaw
深度学习040716 小时前
SVN 独立服务端部署与客户端使用指南(CentOS/Rocky 9.5 + Windows)
windows·svn
爱分享软件的学长17 小时前
Tiled Map Editor 1.12.1 官方版下载(夸克网盘+百度网盘,SHA256校验)
windows·开源软件·软件下载
Dream-Y.ocean17 小时前
鸿蒙PC平台 Carnac 按键显示适配实战:从 Windows 到 HarmonyOS 的 Electron 迁移指南
windows·electron·harmonyos
拾贰_C17 小时前
【mysql | windows | installation】 MySQL5.安装
数据库·windows·mysql
shandianchengzi19 小时前
【记录】Claude Code|Windows11给Claude Code新增任务消息提示音
windows·ai·音频·claude·claude code
瑞雪兆丰年兮21 小时前
[从0开始学Java|第二十五天]项目阶段(综合练习&斗地主小游戏)
java·windows