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

代码地址:

相关推荐
糖果店的幽灵10 小时前
langgraph的 MessagesState 解读
java·开发语言·人工智能·windows·langgraph
骑上单车去旅行11 小时前
MD5校验对比脚本
linux·服务器·windows
FreeBuf_14 小时前
Windows NT OS内核提权漏洞PoC已公开
windows
雲帝15 小时前
Windows虚拟机UDP大包分片排障
windows·网络协议·udp
李少兄15 小时前
Windows 键盘快捷键指南
windows·计算机外设·快捷键
寒水馨16 小时前
Windows下载、安装scrcpy-v4.1(附安装包scrcpy-win64-v4.1.zip)
windows·scrcpy·投屏工具·安卓投屏·usb调试·android投屏·屏幕镜像
神仙别闹16 小时前
基于QT(C++)实现Windows 自启动项查看和分析
c++·windows·qt
love530love1 天前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
光年像素2 天前
Windows Win+R 运行框常用快捷命令大全
windows
寒水馨2 天前
Windows下载、安装ollama-v0.32.1(附安装包OllamaSetup.exe)
windows·llm·大语言模型·llama·本地部署·ollama·模型运行