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 小时前
nuget把缓存搬离C盘
c语言·windows·缓存
love530love3 小时前
ComfyUI 插件发布 GitHub Release + Comfy Registry (官方节点商店)完整复盘教程(从零开始)
人工智能·windows·github·devops
ofoxcoding3 小时前
Windows 上 Codex 报 “failed to start codex app-server“:成因与修复(2026)
windows·ai
每天都进步一点点5 小时前
Windows 系统安装 Python 3.11+ 详细教程
windows·python3.11
开发小程序的之朴6 小时前
安企CMS的安装-PHPStudy(小皮面板)部署
windows·mysql·nginx
love530love6 小时前
【硬核排障 & 猴子补丁 & 幽灵节点】SageAttention GQA 崩溃与 Flash Attention 兼容性修复全记录
ide·人工智能·windows·comfyui·sageattention·windows cuda
John Song16 小时前
ansible-playbook常用的检查命令
windows·ansible
视觉AI17 小时前
VS Code Remote-SSH 连接Jetson踩坑完整解决记录(网段不通+主机密钥变更双重故障)
运维·网络·人工智能·windows·ssh·边缘计算
观远数据1 天前
从离线开发到实时同步:DataFlow如何支撑企业级数据治理闭环
java·windows·microsoft·excel
西西学代码1 天前
Charge-BleMessage
windows