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

代码地址:

相关推荐
阿萨德528号3 小时前
Windows RabbitMQ 启动完整指南(附启动报错解决、如何以服务方式后台运行)
windows·rabbitmq·ruby
私人珍藏库4 小时前
[吾爱大神原创工具] 鼠标轨迹美化工具
windows·工具·鼠标·软件·win·多功能
小小测试开发4 小时前
AI Agent 重构单体应用实战:1Password 经验与避坑指南
人工智能·windows·重构
您^_^4 小时前
专家(一):Claude Code 微服务实战——6 个服务从拆分到 K8s 部署,$0.45 全套 YAML 照抄
人工智能·windows·微服务·架构·kubernetes·个人开发·claude code
TE-茶叶蛋4 小时前
Java 8 引入的Stream API-stream()
java·windows·python
lei_6864 小时前
Microsoft Office Click-to-Run Service关闭服务
windows·microsoft
idolao5 小时前
Python 3.14安装教程 Windows版:环境变量配置+IDLE启动+自定义路径指南
windows
云小逸5 小时前
【 VS2013 集成 Qt5.7.1 踩坑记录:moc/uic/rcc 报“系统找不到指定的路径”怎么解决?】
开发语言·windows·qt
m0_535817557 小时前
告别海外账号!Claude Code Windows完整部署指南:从Node.js到api对接(附避坑)
windows·gpt·node.js·api·claude·claudecode·88api
秋97 小时前
Windows 环境下 Redis 部署详解:从选型、安装到生产级配置与运维
运维·windows·redis