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

代码地址:

相关推荐
22信通小白4 小时前
USRP初学者使用手册(基础配置及bug记录)——Windows+MATLAB
windows·matlab·bug
胡斌附体4 小时前
Windows 打包方式与 exe图标说明
windows·electron·exe·package·build·nsis
小江的记录本5 小时前
【Linux】《Linux常用命令汇总表》
linux·运维·服务器·前端·windows·后端·macos
追烽少年x7 小时前
Windows API中线程异步API简介
windows
私人珍藏库7 小时前
[Windows] 绘画工具 Krita v5.3.1
人工智能·windows·媒体·工具·软件·多功能
tumeng071112 小时前
Node.JS 版本管理工具 Fnm 安装及配置(Windows)
windows·node.js
阿正的梦工坊12 小时前
Mac 的.zshrc在 Windows 上等价怎么做:设置环境变量
windows·macos
csdn2015_12 小时前
List<DocumentMetadata> 取所有docid,组成List<String>
windows·python·list
牢七13 小时前
CVE-2022-37202 nday 研究 sql
linux·windows·microsoft
冰冷的希望13 小时前
【系统】非虚拟机,物理机安装Ubuntu教程,Windows与Linux(Ubuntu)双系统共存!
linux·windows·ubuntu·系统架构·vmware·双系统·pe系统