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

代码地址:

相关推荐
qq_393828222 小时前
电脑休眠设置
windows·电脑·软件需求
网安小白的进阶之路5 小时前
A模块 系统与网络安全 第三门课 网络通信原理-3
网络·windows·安全·web安全·系统安全
芳草萋萋鹦鹉洲哦12 小时前
【vue3+tauri+rust】如何实现下载文件mac+windows
windows·macos·rust
李洋-蛟龙腾飞公司12 小时前
HarmonyOS NEXT应用元服务常见列表操作多类型列表项场景
windows
new_zhou17 小时前
Windows qt打包编译好的程序
开发语言·windows·qt·打包程序
Rocket MAN17 小时前
Rovo Dev CLI Windows 安装与使用指南
windows
fzyz12321 小时前
Windows系统下WSL从C盘迁移方案
人工智能·windows·深度学习·wsl
csdn_aspnet1 天前
在 Windows 机器上安装和配置 RabbitMQ
windows·rabbitmq
csdn_aspnet1 天前
Windows Server 上的 RabbitMQ 安装和配置
windows·rabbitmq
热爱生活的猴子1 天前
Poetry 在 Linux 和 Windows 系统中的安装步骤
linux·运维·windows