diff --git a/Tutorial/GacUI_Xml/Binding_ViewModel/Main.cpp b/Tutorial/GacUI_Xml/Binding_ViewModel/Main.cpp index e64bc96a..9811e524 100644 --- a/Tutorial/GacUI_Xml/Binding_ViewModel/Main.cpp +++ b/Tutorial/GacUI_Xml/Binding_ViewModel/Main.cpp @@ -9,6 +9,15 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi return SetupWindowsDirect2DRenderer(); } +class ViewModelImpl : public Object, public virtual demo::IViewModel +{ +public: + WString GetMessageFromName(WString name)override + { + return L"Hi, " + name + L"! How are you?"; + } +}; + void GuiMain() { { @@ -17,7 +26,7 @@ void GuiMain() auto resource = GuiResource::LoadPrecompiledBinary(fileStream, errors); GetResourceManager()->SetResource(L"Resource", resource); } - demo::MainWindow window; + demo::MainWindow window(new ViewModelImpl); window.MoveToScreenCenter(); GetApplication()->Run(&window); } \ No newline at end of file diff --git a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Resource.xml b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Resource.xml index f60677fb..4123a1e4 100644 --- a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Resource.xml +++ b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Resource.xml @@ -13,13 +13,50 @@ + + - + + + composeType:MinSize + composeType:MinSize + composeType:Percentage percentage:1.0 + + + composeType:MinSize + composeType:Absolute absolute:100 + composeType:Percentage percentage:1.0 + + + + + + + + + + + + + +
diff --git a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.cpp b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.cpp index aa0483a1..e3d76e68 100644 --- a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.cpp +++ b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.cpp @@ -16,9 +16,9 @@ namespace demo // #endregion CLASS_MEMBER_GUIEVENT_HANDLER - MainWindow::MainWindow() + MainWindow::MainWindow(Ptr ViewModel) { - InitializeComponents(); + InitializeComponents(ViewModel); } MainWindow::~MainWindow() @@ -35,11 +35,19 @@ namespace vl namespace description { #define _ , + IMPL_CPP_TYPE_INFO(demo::IViewModel) IMPL_CPP_TYPE_INFO(demo::MainWindow) + BEGIN_CLASS_MEMBER(demo::IViewModel) + CLASS_MEMBER_BASE(vl::reflection::IDescriptable) + CLASS_MEMBER_METHOD(GetMessageFromName, { L"name" }); + END_CLASS_MEMBER(demo::IViewModel) + BEGIN_CLASS_MEMBER(demo::MainWindow) CLASS_MEMBER_BASE(vl::presentation::controls::GuiWindow) - CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(), NO_PARAMETER) + CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(Ptr), { L"ViewModel" }) + + CLASS_MEMBER_PROPERTY_READONLY_FAST(ViewModel) END_CLASS_MEMBER(demo::MainWindow) #undef _ @@ -49,6 +57,7 @@ namespace vl public: void Load(ITypeManager* manager) { + ADD_TYPE_INFO(demo::IViewModel) ADD_TYPE_INFO(demo::MainWindow) } diff --git a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.h b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.h index 8088a85f..7a5ad841 100644 --- a/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.h +++ b/Tutorial/GacUI_Xml/Binding_ViewModel/UI/Source/DemoPartialClasses.h @@ -15,30 +15,48 @@ DO NOT MODIFY namespace demo { + class IViewModel; class MainWindow; + class IViewModel : public virtual vl::reflection::IDescriptable, public vl::reflection::Description + { + public: + virtual vl::WString GetMessageFromName(vl::WString name) = 0; + }; + template class MainWindow_ : public vl::presentation::controls::GuiWindow, public vl::presentation::GuiInstancePartialClass, public vl::reflection::Description { friend struct vl::reflection::description::CustomTypeDescriptorSelector; private: + Ptr ViewModel_; protected: + vl::presentation::controls::GuiSinglelineTextBox* textBoxName; - void InitializeComponents() + void InitializeComponents(Ptr ViewModel) { + ViewModel_ = ViewModel; if (InitializeFromResource()) { + GUI_INSTANCE_REFERENCE(textBoxName); } else { + ViewModel_ = 0; } } public: MainWindow_() :vl::presentation::GuiInstancePartialClass(L"demo::MainWindow") ,vl::presentation::controls::GuiWindow(vl::presentation::theme::GetCurrentTheme()->CreateWindowStyle()) + ,textBoxName(0) { } + + Ptr GetViewModel() + { + return ViewModel_; + } }; } @@ -48,6 +66,7 @@ namespace vl { namespace description { + DECL_TYPE_INFO(demo::IViewModel) DECL_TYPE_INFO(demo::MainWindow) } @@ -64,7 +83,7 @@ namespace demo // #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.) // #endregion CLASS_MEMBER_GUIEVENT_HANDLER public: - MainWindow(); + MainWindow(Ptr ViewModel); ~MainWindow(); }; } diff --git a/Tutorial/GacUI_Xml/UIRes/Binding_ViewModel.bin b/Tutorial/GacUI_Xml/UIRes/Binding_ViewModel.bin index 11040e6e..b71dfd71 100644 Binary files a/Tutorial/GacUI_Xml/UIRes/Binding_ViewModel.bin and b/Tutorial/GacUI_Xml/UIRes/Binding_ViewModel.bin differ diff --git a/Tutorial/README.md b/Tutorial/README.md index 045061fe..6bb8e575 100644 --- a/Tutorial/README.md +++ b/Tutorial/README.md @@ -32,11 +32,11 @@ GacUI tutorials and the plan * **Instance_Window**: Create a window. * **Instance_MultipleWindows**: Create multiple windows. * **Instance_Control**: Create a control. - * **Binding_Uri**: Using -uri binding. (developing) - * **Binding_Eval**: Using -eval binding. (developing) - * **Binding_Bind**: Using -bind binding. (developing) - * **Binding_Format**: Using -format binding. (developing) - * **Binding_ViewModel**: Binding to view model. (developing) + * **Binding_Uri**: Using -uri binding. + * **Binding_Eval**: Using -eval binding. + * **Binding_Bind**: Using -bind binding. + * **Binding_Format**: Using -format binding. + * **Binding_ViewModel**: Binding to view model. * **Event_Cpp**:Handling event in C++. (developing) * **Event_Script**:Handling event in Workflow script. (developing) * **Event_ViewModel**:Handling event in view model. (developing)