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

代码地址:

相关推荐
露天赏雪1 分钟前
JDK8 的入门避坑指南
java·服务器·windows·spring boot·后端·spring·性能优化
仗剑天涯 回首枉然27 分钟前
Linux 和 windows 共享文件
linux·运维·windows
良逍Ai出海30 分钟前
在 Windows & macOS 上安装 Claude Code,并使用第三方 Key 的完整教程
windows·macos
404Clukay30 分钟前
Windows Server 配置 Let‘s Encrypt 免费 HTTPS 证书(WACS + Nginx 自动化方案)
windows·nginx·https
❀搜不到38 分钟前
windows 使用MinGW安装Nlopt
windows
凸头1 小时前
PostgreSQL 16 中文分词插件 zhparser 在 Windows 11 上的编译与安装
windows·postgresql·中文分词
love530love1 小时前
【实战经验】解决ComfyUI加载报错:PytorchStreamReader failed reading zip archive: failed finding central directory
人工智能·windows·python·ai作画·aigc·comfyui·攻关
IT技术分享社区2 小时前
科技资讯:微软确认广泛推送Windows 11新版开始菜单,并解释再次“重新设计”的原因
windows·科技·microsoft
玉梅小洋2 小时前
Android SDK 安装指南(MacOS 和 Windows)
android·windows·macos·sdk
一个人旅程~2 小时前
电脑启动分区表MBR到GPT以及BIOS到UEFI如何区分操作?
linux·windows·电脑