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

代码地址:

相关推荐
Chief_fly2 小时前
【Windows 下载 ARM64 deb 包 麒麟 ARM 离线安装】
arm开发·windows
阿昭L2 小时前
ZwQuerySystemInformation通过PsLoadedModuleList枚举内核模块
windows·逆向工程·windows内核
桑榆4166 小时前
双系统(Windows + Ubuntu)安装流程
linux·windows·ubuntu
走,带你去玩15 小时前
windows电脑 trae对接lanhu-mcp
windows
戒了,最后一次21 小时前
Windows 安装 FFmpeg 完整教程(附环境变量配置 + 常用命令示例)
windows·ffmpeg
liulilittle1 天前
DeepSeek Harness 自定义模型提供商配置
前端·javascript·人工智能·windows·llm·deepseek·harness
fruge1 天前
Windows部署MiGPT GUI:小爱音箱接入大模型、TTS与自定义人设
windows
源码学社1 天前
DeerFlow Windows 本地运行教程(uv)
windows·uv·沙箱·deerflow·超级智能体·deerflow安装
Sombra_Olivia1 天前
复现Windows Server服务RPC请求缓冲区溢出漏洞(MS08067)
网络·windows·安全·web安全·网络安全·渗透测试·vulhub
-天道酬勤-1 天前
查看Windows电脑开机时间
windows·电脑