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

代码地址:

相关推荐
百事牛科技7 小时前
WinRAR注释功能:给压缩包留个便签
windows·winrar
sukalot8 小时前
Windows 驱动实例分析系列:libwdi 驱动分析 - examples 篇(一)
windows·驱动开发
加载力科技8 小时前
硬盘咔咔响是坏盘信号!赶在数据丢失前克隆换盘:不重装系统、不丢文件
windows·嵌入式硬件·系统安全·策略模式·命令模式·硬盘
2601_9623649710 小时前
电脑人脸解锁的安全基石,聊聊 Windows Hello 硬件规范
windows·安全·电脑
MIXLLRED15 小时前
Windows 搭建《动手学深度学习》PyTorch 环境:从安装到踩坑记录
pytorch·windows·深度学习
fogota15 小时前
C# `string.Join` 处理 `List<int>`
windows·c#
律宏阔1 天前
WSL Docker 端口明明空闲,但就是绑不上端口
linux·windows
律宏阔1 天前
Windows 禁用联想笔记本所有 Lenovo 后台服务
windows
律宏阔1 天前
WSL 突然断网,无法 ping 内网或外网
linux·windows
小羊没烦恼!7 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#