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

代码地址:

相关推荐
苏生Susheng6 小时前
【软件实施】Windows 服务器运维实战
java·运维·服务器·windows·spring boot·javaweb·实施
方向研究7 小时前
UEFI/Windows启动流程
windows
ZnS_oscar7 小时前
不用下载字体,获得仿宋字体
windows·word
霸道流氓气质7 小时前
通义千问 Chat 模型高级用法:Function Calling / Structured Output / 多轮对话
linux·运维·windows
Boop_wu8 小时前
[LangGraph] 案例 2 : 支持搜索的智能代理系统
服务器·windows·python·langchain
啦啦啦~~~2228 小时前
PC端+安卓端阅读器推荐!开源本地小说阅读器软件,
android·论文阅读·windows·开源软件·福昕阅读器
C++ 老炮儿的技术栈9 小时前
Qt5 使用 QPainter 绘制阿基米德螺线
开发语言·c++·windows·qt·代码化
今日热点10 小时前
Windows 系统 C 盘深度清理教程:安全释放存储空间,避开误删风险
windows·安全
gsls20080811 小时前
告别 Vault 的复杂度:用 Go 标准库给 Windows 凭据管理器装上 MCP
windows·golang·mcp
Mrs_DongDong11 小时前
华为云 Windows 服务器远程桌面自定义端口排障指南
服务器·windows·华为云