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

代码地址:

相关推荐
云小逸8 小时前
【nmap源码解析】Nmap 核心技术深度解析:从源码到实战
开发语言·网络·windows·nmap
不会飞的鲨鱼9 小时前
新手windows新电脑配置(暂停更新,node配置)
windows
liwulin050615 小时前
【ESP32-S3】WINDOWS+VMware+ROS2+YDLIDA X2导航初步调试
windows·stm32·单片机
xiaoliuliu1234516 小时前
银河麒麟V10安装 openssl-1.1.1f-4.p12.ky10.x86_64.rpm 教程(含依赖解决)
windows
最贪吃的虎16 小时前
windows上如何可视化访问并远程操作linux系统上运行的浏览器或者linux可视化桌面
java·linux·运维·windows·分布式·后端·架构
rhett. li16 小时前
Windows系统中使用MinGW-W64(gcc/g++或LLVM)编译Skia源码的方法
c++·windows·ui·用户界面
bug智造16 小时前
Windows右下角时间不显示秒
windows
徐先生 @_@|||16 小时前
Windows 的高级进程监视器Microsoft - Process Monitor
windows
非凡ghost17 小时前
Ookla Speedtest安卓版(网速测试工具)
android·windows·学习·智能手机·软件需求
Volunteer Technology17 小时前
LangGraph的WorkFlow(二)
linux·windows·python