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

代码地址:

相关推荐
曹牧12 小时前
C#:`JsonConvert.DeserializeObject`
windows·c#
JckOLF04Z14 小时前
软件项目“免坑”指南
windows
imperialeast15 小时前
WinAXP音乐播放器8月4日更新
windows·算法·ui
aGdF8E3gQ16 小时前
16. LangChain ChatPromptTemplate多模态应用实战
windows·langchain
IT小盘16 小时前
17-构建Prompt测试集-提示词优化不再凭感觉
服务器·windows·prompt
神奇霸王龙18 小时前
Agent 5 场景屠夫:跨厂商基座横评
人工智能·windows·ai·dubbo·agent·ai编程·阿里
柒@宝儿姐19 小时前
若依 B 端从浏览器访问升级为 Windows 安装包交付流程
前端·javascript·vue.js·windows
肖恭伟19 小时前
MinerU 新手完整配置教程:Windows 下将 PDF 转为带图片的 Markdown
windows·pdf
梓沂20 小时前
Oracle 11g 跨平台迁移实战:从 Windows 到 CentOS 的完整记录
windows·oracle·centos
yagami_gagami20 小时前
第四届黄河流域公安院校电子物证个人赛程序逆向分析
android·windows·网络安全