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

代码地址:

相关推荐
2601_962364972 小时前
Windows Hello 人脸解锁,指纹和红外摄像头哪个更安全?
windows·安全
纪念 2292 小时前
C++ list讲解
c++·windows·list
半拉老头5 小时前
用360安全浏览器插件图片助手批量下载图片
windows
Vex2une15 小时前
Docker Desktop WSL2后端:2026年性能调优与避坑实战指南
windows·docker·desktop·gpu容器·容器开发·virtiofs·buildkit
钱栈up16 小时前
搜狗中文模式打不出顿号?在 Windows 沙箱里探测输入法配置的踩坑实录
windows
白搞电子17 小时前
ZeroClaw 是什么?与 ESP-Claw 的区别及文件整理用途示例
windows·物联网
BeiGuTing_code18 小时前
Java动态数组(一)
java·数据结构·windows
我就是不信21 小时前
Java8 lambda 表达式 forEach 如何提前终止?
开发语言·windows·python
陈工大模型1 天前
2026 Windows 免费压缩软件横向评测:7-Zip、WinRAR、Bandizip、NanaZip 与 Win 解压缩
windows·电脑·winrar·7-zip·web app·软件·win解压缩
燃烧的枫1 天前
Windows 下 YOLO26 的 TensorRT C++ 部署
人工智能·pytorch·windows·计算机视觉·tensorrt·cuda·yolo26