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

代码地址:

相关推荐
技术不好的崎鸣同学2 小时前
第一章:PEB结构解析与内存定位
windows·安全·系统安全
江湖人称菠萝包6 小时前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter1-基础知识
windows·笔记
白山编程大哥6 小时前
Java 迭代器接口详解:从 Iterator 到 ListIterator 的完整指南
java·开发语言·windows
一叶龙洲6 小时前
Ubuntu从图标到卸载应用
linux·windows·ubuntu
江湖人称菠萝包7 小时前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter2-Windows窗口程序
windows·笔记
奈斯先生Vector8 小时前
AIGC 视频生成实战:用 Kling Video 拆解文生视频、图生视频与完整工作流
开发语言·人工智能·windows·python·aigc·音视频
暖焰核心9 小时前
迭代器与模板的结合——stl的list
c++·windows·list
2401_861678629 小时前
Git 在 Windows 使用
windows·git·elasticsearch
en.en..12 小时前
LVGL 普通函数指针与结构体函数指针原理
linux·windows·microsoft
今夕资源网12 小时前
Windows 本地 HTTPS 配置教程:使用 CertTool 创建自签名证书并部署到宝塔
windows·网络协议·https