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

代码地址:

相关推荐
夜雪一千8 小时前
Python enumerate() 函数完整详解:遍历同时获取索引,告别手动计数
服务器·windows·python
问简18 小时前
【共享盘】ubuntu、windows
linux·windows·ubuntu
公子小六19 小时前
基于.NET的Windows窗体编程之WinForms图像控件
windows·microsoft·c#·.net·winforms
狂热开发者20 小时前
用 Typeoff 把会后口述整理成 Markdown 决策记录
人工智能·windows·macos·ios·安卓
何中应20 小时前
Windows7 虚拟机如何传文件
windows·vmware·虚拟机
一只小bit20 小时前
LangChain 核型组件与消息管理及提示词模版
windows·microsoft·langchain
ofoxcoding21 小时前
Codex Computer Use 完整指南:AI 自动操控 Mac 与 Windows 桌面实战详解
人工智能·windows·macos·ai
Nontee21 小时前
Set 这个东西,跟我一开始想的不太一样
java·linux·windows·microsoft
XUHUOJUN1 天前
Windows Server 2025 Stretch Cluster 架构详解
windows·microsoft·azure local
大蚂蚁2号1 天前
Fuck Stop code: VIDEO_DXGKRNL_FATAL_ERROR (0x113)
windows·系统架构