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

代码地址:

相关推荐
一个人旅程~1 小时前
linux如何“抢”过windows的usb移动硬盘权限对0磁道损坏的移动硬盘进行尝试修复
linux·windows·经验分享·电脑
Keano Reurink2 小时前
长尾关键词自动化扩展:从1个种子词到1000个长尾词
运维·windows·自动化
新时代农民工~3 小时前
PostgreSQL 主从复制(流复制)实战配置指南:Windows 环境详细步骤
数据库·windows·postgresql
AI周红伟4 小时前
通用业务智能体OpenClaw+Skills+RAG+Agent构建案例实操
大数据·人工智能·windows·百度·copilot
a58808114 小时前
WarCraft III《魔兽争霸3冰封王座》原版安装包——游戏玩法、配置要求与详细安装教程
windows·游戏·游戏程序
Chirp6 小时前
Windows下借助wsl2读取ext4格式磁盘
linux·windows
CAE虚拟与现实8 小时前
img格式的文件在windows上怎么打开
windows·img文件·微软img
a58808119 小时前
星际争霸1原版安装包——游戏玩法、配置要求与详细安装教程
windows·游戏·游戏程序
A懿轩A10 小时前
Claude Code 2026 最新版下载安装教程详细版 涵盖Windows 和 MacOS 安装 附常见问题解决方案
windows·macos
dhjabc_110 小时前
Windows 超完整配置 OpenCode 教程(改D盘安装+永久国内镜像+全套使用指南)
windows