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

代码地址:

相关推荐
黄一一9112431 小时前
硬盘健康监测软件!绿色便携版!电脑硬盘还能用几年?CrystalDiskInfo工具帮你提前避开数据丢失
windows·电脑·硬件工程·开源软件
奇牙coding2 小时前
gpt-5.6-luna 调用报 400 bad_request 怎么办?同样的 messages 在 gpt-5.5 没问题——两处校验差异和修复写法
java·windows·gpt·ai
樂禮2 小时前
Windows-Arch Linux 键鼠共享 & 剪贴板同步配置
linux·运维·windows
未来可期丶2 小时前
【开发环境】Windows+Docker Desktop+WSL2最佳实践
windows·docker·docker desktop·wsl2
2501_9419820511 小时前
企业微信二次开发:私域数据基石——三大核心基础能力接口实战
windows·架构·bootstrap·企业微信
美丽的欣情20 小时前
RK3588 Debian 交叉编译环境搭建(Windows + VMware Debian + CMake)
运维·windows·debian
勤劳打代码21 小时前
Flutter 架构指南 —— windows 平台安装拆解
windows·架构
aramae1 天前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
执行x1 天前
wsl2安装+桥接模式+固定IP
linux·windows·ubuntu
做萤石二次开发的哈哈1 天前
如何接入萤石开放平台 ERTC Windows SDK?
windows·音视频·萤石开放平台