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

代码地址:

相关推荐
90后小陈老师8 小时前
Windows 10 下 Gitee SSH 连接配置详解(附常见问题解决)
windows·gitee·ssh
Light Gao9 小时前
MCPHub 路由原理:一个入口如何管理并调用上百个 MCP Server
windows·microsoft
郭涤生10 小时前
Windows + Ubuntu 双系统启动故障修复
linux·windows·ubuntu
看浪的路人16 小时前
第3讲:代码补全引擎
开发语言·windows·python
进击切图仔18 小时前
在 windows 和 ubuntu 中配置 host 文件
linux·windows·ubuntu
烟锁池塘柳018 小时前
【亲测有效】Windows上更新NVIDIA显卡驱动的方法
windows·nvidia·显卡驱动
看浪的路人20 小时前
第5讲:代码审查与 Bug 检测
开发语言·windows·python
molaoye1 天前
Windows修改系统环境变量不需要重启电脑之骚操作
windows
wling03011 天前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
在世修行2 天前
Windows 上 Docker Desktop 部署 MySQL + TDengine 全过程(含 WSL 报错与镜像加速排障实战)
windows·mysql·docker·tdengine