Skip to content

witsanchenc/mvvmlight-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CppMvvm - C++ MVVM Light Framework

一个用纯C++实现的MVVM Light框架,Qt仅作为界面层,提供C#风格的发布订阅模式。

特性

  • ✅ C#风格的事件系统
  • ✅ 属性变更通知
  • ✅ 命令模式
  • ✅ 消息传递
  • ✅ 资源清理
  • ✅ Qt集成
  • ✅ 跨平台支持

技术栈

  • C++17/20
  • Qt6 (仅用于界面)
  • CMake构建系统

项目结构

cppmvvm/
├── include/MvvmLight/     # 头文件
├── src/                   # 源文件
├── examples/              # 示例代码
├── tests/                 # 单元测试
└── docs/                  # 文档

快速开始

#include "MvvmLight/core/ViewModelBase.hpp"
#include "MvvmLight/commands/RelayCommand.hpp"

class MainViewModel : public MvvmLight::ViewModelBase {
public:
    MainViewModel() {
        buttonCommand_ = std::make_shared<MvvmLight::RelayCommand>(
            [this]() { onButtonClicked(); }
        );
    }
    
    const std::string& title() const { return title_; }
    void setTitle(const std::string& title) {
        setProperty(title_, title, "Title");
    }
    
    std::shared_ptr<MvvmLight::ICommand> buttonCommand() const { 
        return buttonCommand_; 
    }

private:
    void onButtonClicked() {
        setTitle("Button Clicked!");
    }
    
    std::string title_ = "Hello World";
    std::shared_ptr<MvvmLight::ICommand> buttonCommand_;
};

构建

mkdir build
cd build
cmake ..
make

许可证

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published