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

代码地址:

相关推荐
jack186898 小时前
百度 AI 搜索实战:从精准获客到智能决策的应用全景
windows
道满科技9 小时前
Function Calling 参数总出错?只修参数就行
linux·windows·python
GHN198788810 小时前
开源小工具按一下空格,什么都看见了
windows
围炉聊科技12 小时前
Windows-MCP 拆解与实测:AI 操作 Windows 这件事——智能体基建系列
windows·llm·dom
面包狗AI4S13 小时前
ChatGPT/Codex Windows:本地桌面端应用离线包安装与免安装启动方法(无需管理员权限)
人工智能·windows·ai·chatgpt
自养Agent14 小时前
MCP Server Boundary Audit Report
linux·服务器·人工智能·windows·大模型·llm
2301_7867566016 小时前
中科院分区表停发后,期刊评价的技术逻辑:从期刊超越指数到多指标选刊方案
java·数据库·windows
是我知白哒18 小时前
下载的图片Windows上无法设置为屏保如何解决
windows
Vex2une18 小时前
获取 PowerToys - 从系统外挂工具到开源效率平台
windows·开源·效率工具·powertoys·fancyzones·command palette·键盘管理器
骇客野人20 小时前
Windows 安全清理临时文件 bat 脚本
windows·安全