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 小时前
基于.NET的Windows窗体编程之WinForms滑块与上下控件
windows·microsoft·c#·.net·winforms
学海浪太大6 小时前
笔记本电脑插入显示器没反应
windows
黄一一9112438 小时前
告别手动敲字,本地截图 OCR,识别完直接复制!开源截图识别工具
windows·ocr·开源软件·贴图
洪流之源9 小时前
Windows 远程 Ubuntu 24.04 桌面
linux·windows·ubuntu
是小李呀10 小时前
Windows 虚拟内存配置完全指南:从原理到实操,彻底解决内存不足与 OOM 问题
windows
毕竟是shy哥12 小时前
windows电脑WSL下本地构建docker镜像
windows·docker·容器
kakakahahahaha1 天前
【Windows】C盘低空间反复复发的排查与扩容边界
c语言·windows·电脑·笔记本电脑·内容运营·软件需求
2301_800074211 天前
map,list简单方法
windows·python·list
技术不好的崎鸣同学1 天前
Windows 红队实战:前言
windows
吴声子夜歌1 天前
Guava——基本工具(二)
windows·python·guava