行业知识
WPF使用Prism实现简单订餐系统
2026-11-12 07:02:52
来源:互联网转载
新建wpf项目,nuget引入Prism.DryIoc,MaterialDesignThemes
引入后,修改App.xaml 前台引入 xmlns:prism="http://prismlibrary.com/"和prism:PrismApplication App.xaml.cs
App.xaml.cs继承PrismApplication,重写CreateShell和RegisterTypes
protected override Window CreateShell() { return Container.Resolve(); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { } MainWindowViewModel继承BindableBase,实现mvvm
上面步骤,同样可以通过新建prism 项目,自动引入引入了prism
在model中新建属性,实现属性自动通知功能
private double _total; public double Total { get { return _total; } set { _total = value; RaisePropertyChanged(); } } 前台绑定
新建Command
public DelegateCommand SelCommand { get; set; }
在构造函数中,绑定委托方法
SelCommand = new DelegateCommand(()=> {
SelectDish();
DispAllSelect();
});
如果方法带有参数,可以使用DelegateCommand泛型声明
前台绑定控件Command属性调用
最后实现简单的Order系统
代码地址: