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

代码地址:

相关推荐
ysu_031439 分钟前
Docker-Desktop-WSL2实战指南-Windows从安装配置到项目容器化
windows·python·docker·容器·composer·dockerfile·wsl2
shimly1234561 小时前
(undone) 解析 qemu-6.0.0 源码 (4) 添加 niubi board
windows
柳鲲鹏3 小时前
安装WIN11(26H2)时,忽略跳过TPM和SecureBoot检查
windows
weixin1997010801615 小时前
《1688物流API接口边界:logistics.trace.get 与 freight.template.list 的隐藏约束》(附Python源码)
windows·python·list
爱编程的Zion1 天前
【踩坑记录】同一个 WiFi 下,A 电脑能访问 192.168.0.115,B 电脑死活不行 ——Windows 路由表缺失引发的故障排查
windows·电脑
Qwier1 天前
Win Srv 2019 安装补丁后重启
运维·服务器·windows
lusklusklusk1 天前
Python 四大数据结构详解:元组、列表、集合、字典的特点与增删改查
数据结构·windows·python
今年下半年1 天前
【运维】windows虚拟机安装arm(aarch64)服务器
运维·windows·arm·虚拟机·aarch64
浪潮IT馆1 天前
Windows 10 安装 PostgreSQL 9.6.24 完整教程
数据库·windows·postgresql
sukalot1 天前
Windows 驱动实例分析系列:libwdi 驱动分析 - libwdi 篇(一)
windows