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

代码地址:

相关推荐
程序猿小D10 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
iummature12 小时前
ZLMediaKit Windows编译以及使用
windows
周伯通*15 小时前
Windows上,使用远程桌面连接Ubuntu
linux·windows·ubuntu
GDAL17 小时前
GNU力量注入Windows:打造高效跨平台开发新纪元
服务器·windows·gnu
小徐敲java20 小时前
Windows本地制作java证书(与jeecgboot配置本地证书ssl问题)
java·windows·ssl
春蕾夏荷_72829772520 小时前
electron nsis打包windows应用程序
javascript·windows·electron·nsis
偷偷小野猪21 小时前
Windows 常用的键盘快捷键总结
windows
Splashtop高性能远程控制软件1 天前
centos远程桌面连接windows
linux·windows·centos·远程控制·远程桌面
楚钧艾克1 天前
Windows系统通过部署wsl + Goland进行跨平台开发
linux·windows·后端·ubuntu·golang
wow2ok1 天前
天融信把桌面explorer.exe删了,导致开机之后无windows桌面,只能看到鼠标解决方法
windows·计算机外设