Demo: GacUI_Xml\Binding_ViewModel

This commit is contained in:
vczh
2016-04-14 00:36:47 -07:00
parent 205867b7a3
commit a1f680a715
6 changed files with 88 additions and 14 deletions
+10 -1
View File
@@ -9,6 +9,15 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
return SetupWindowsDirect2DRenderer(); 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() void GuiMain()
{ {
{ {
@@ -17,7 +26,7 @@ void GuiMain()
auto resource = GuiResource::LoadPrecompiledBinary(fileStream, errors); auto resource = GuiResource::LoadPrecompiledBinary(fileStream, errors);
GetResourceManager()->SetResource(L"Resource", resource); GetResourceManager()->SetResource(L"Resource", resource);
} }
demo::MainWindow window; demo::MainWindow window(new ViewModelImpl);
window.MoveToScreenCenter(); window.MoveToScreenCenter();
GetApplication()->Run(&window); GetApplication()->Run(&window);
} }
@@ -13,13 +13,50 @@
</Folder> </Folder>
</Folder> </Folder>
<Folder name="MainWindow"> <Folder name="MainWindow">
<Script name="ViewModelResource">
<Workflow-ViewModel>
module script;
namespace demo
{
interface IViewModel
{
func GetMessageFromName(name : string) : string;
}
}
</Workflow-ViewModel>
</Script>
<Instance name="MainWindowResource"> <Instance name="MainWindowResource">
<Instance ref.CodeBehind="false" ref.Class="demo::MainWindow"> <Instance ref.CodeBehind="false" ref.Class="demo::MainWindow">
<ref.Parameter Name="ViewModel" Class="demo::IViewModel"/>
<Window Text="Binding_ViewModel" ClientSize="x:480 y:320"> <Window Text="Binding_ViewModel" ClientSize="x:480 y:320">
<att.BoundsComposition-set PreferredMinSize="x:480 y:320"/> <att.BoundsComposition-set PreferredMinSize="x:480 y:320"/>
<Label Text="This is a window!"> <Table CellPadding="5" MinSizeLimitation="LimitToElementAndChildren" AlignmentToParent="left:0 top:0 right:0 bottom:0">
<att.Font>fontFamily:{Segoe UI} size:32 antialias:true</att.Font> <att.Rows>
</Label> <CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Rows>
<att.Columns>
<CellOption>composeType:MinSize</CellOption>
<CellOption>composeType:Absolute absolute:100</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Columns>
<Cell Site="row:0 column:0" InternalMargin="left:0 top:5 right:0 bottom:5">
<Label Text="Type your name : "/>
</Cell>
<Cell Site="row:0 column:1">
<SinglelineTextBox ref.Name="textBoxName" Text="Jack">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0" PreferredMinSize="y:24"/>
</SinglelineTextBox>
</Cell>
<Cell Site="row:1 column:0 columnSpan:2" InternalMargin="left:0 top:5 right:0 bottom:5">
<Label Text-bind="ViewModel.GetMessageFromName(textBoxName.Text)"/>
</Cell>
</Table>
</Window> </Window>
</Instance> </Instance>
</Instance> </Instance>
@@ -16,9 +16,9 @@ namespace demo
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER // #endregion CLASS_MEMBER_GUIEVENT_HANDLER
MainWindow::MainWindow() MainWindow::MainWindow(Ptr<demo::IViewModel> ViewModel)
{ {
InitializeComponents(); InitializeComponents(ViewModel);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@@ -35,11 +35,19 @@ namespace vl
namespace description namespace description
{ {
#define _ , #define _ ,
IMPL_CPP_TYPE_INFO(demo::IViewModel)
IMPL_CPP_TYPE_INFO(demo::MainWindow) 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) BEGIN_CLASS_MEMBER(demo::MainWindow)
CLASS_MEMBER_BASE(vl::presentation::controls::GuiWindow) CLASS_MEMBER_BASE(vl::presentation::controls::GuiWindow)
CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(), NO_PARAMETER) CLASS_MEMBER_CONSTRUCTOR(demo::MainWindow*(Ptr<demo::IViewModel>), { L"ViewModel" })
CLASS_MEMBER_PROPERTY_READONLY_FAST(ViewModel)
END_CLASS_MEMBER(demo::MainWindow) END_CLASS_MEMBER(demo::MainWindow)
#undef _ #undef _
@@ -49,6 +57,7 @@ namespace vl
public: public:
void Load(ITypeManager* manager) void Load(ITypeManager* manager)
{ {
ADD_TYPE_INFO(demo::IViewModel)
ADD_TYPE_INFO(demo::MainWindow) ADD_TYPE_INFO(demo::MainWindow)
} }
@@ -15,30 +15,48 @@ DO NOT MODIFY
namespace demo namespace demo
{ {
class IViewModel;
class MainWindow; class MainWindow;
class IViewModel : public virtual vl::reflection::IDescriptable, public vl::reflection::Description<IViewModel>
{
public:
virtual vl::WString GetMessageFromName(vl::WString name) = 0;
};
template<typename TImpl> template<typename TImpl>
class MainWindow_ : public vl::presentation::controls::GuiWindow, public vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>, public vl::reflection::Description<TImpl> class MainWindow_ : public vl::presentation::controls::GuiWindow, public vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>, public vl::reflection::Description<TImpl>
{ {
friend struct vl::reflection::description::CustomTypeDescriptorSelector<TImpl>; friend struct vl::reflection::description::CustomTypeDescriptorSelector<TImpl>;
private: private:
Ptr<demo::IViewModel> ViewModel_;
protected: protected:
vl::presentation::controls::GuiSinglelineTextBox* textBoxName;
void InitializeComponents() void InitializeComponents(Ptr<demo::IViewModel> ViewModel)
{ {
ViewModel_ = ViewModel;
if (InitializeFromResource()) if (InitializeFromResource())
{ {
GUI_INSTANCE_REFERENCE(textBoxName);
} }
else else
{ {
ViewModel_ = 0;
} }
} }
public: public:
MainWindow_() MainWindow_()
:vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>(L"demo::MainWindow") :vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>(L"demo::MainWindow")
,vl::presentation::controls::GuiWindow(vl::presentation::theme::GetCurrentTheme()->CreateWindowStyle()) ,vl::presentation::controls::GuiWindow(vl::presentation::theme::GetCurrentTheme()->CreateWindowStyle())
,textBoxName(0)
{ {
} }
Ptr<demo::IViewModel> GetViewModel()
{
return ViewModel_;
}
}; };
} }
@@ -48,6 +66,7 @@ namespace vl
{ {
namespace description namespace description
{ {
DECL_TYPE_INFO(demo::IViewModel)
DECL_TYPE_INFO(demo::MainWindow) DECL_TYPE_INFO(demo::MainWindow)
} }
@@ -64,7 +83,7 @@ namespace demo
// #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.) // #region CLASS_MEMBER_GUIEVENT_HANDLER (DO NOT PUT OTHER CONTENT IN THIS #region.)
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER // #endregion CLASS_MEMBER_GUIEVENT_HANDLER
public: public:
MainWindow(); MainWindow(Ptr<demo::IViewModel> ViewModel);
~MainWindow(); ~MainWindow();
}; };
} }
Binary file not shown.
+5 -5
View File
@@ -32,11 +32,11 @@ GacUI tutorials and the plan
* **Instance_Window**: Create a window. * **Instance_Window**: Create a window.
* **Instance_MultipleWindows**: Create multiple windows. * **Instance_MultipleWindows**: Create multiple windows.
* **Instance_Control**: Create a control. * **Instance_Control**: Create a control.
* **Binding_Uri**: Using -uri binding. (developing) * **Binding_Uri**: Using -uri binding.
* **Binding_Eval**: Using -eval binding. (developing) * **Binding_Eval**: Using -eval binding.
* **Binding_Bind**: Using -bind binding. (developing) * **Binding_Bind**: Using -bind binding.
* **Binding_Format**: Using -format binding. (developing) * **Binding_Format**: Using -format binding.
* **Binding_ViewModel**: Binding to view model. (developing) * **Binding_ViewModel**: Binding to view model.
* **Event_Cpp**:Handling event in C++. (developing) * **Event_Cpp**:Handling event in C++. (developing)
* **Event_Script**:Handling event in Workflow script. (developing) * **Event_Script**:Handling event in Workflow script. (developing)
* **Event_ViewModel**:Handling event in view model. (developing) * **Event_ViewModel**:Handling event in view model. (developing)