mirror of
https://github.com/vczh-libraries/Release.git
synced 2026-05-21 22:51:26 +08:00
Demo: GacUI_Xml\Binding_ViewModel
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -13,13 +13,50 @@
|
||||
</Folder>
|
||||
</Folder>
|
||||
<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 ref.CodeBehind="false" ref.Class="demo::MainWindow">
|
||||
<ref.Parameter Name="ViewModel" Class="demo::IViewModel"/>
|
||||
<Window Text="Binding_ViewModel" ClientSize="x:480 y:320">
|
||||
<att.BoundsComposition-set PreferredMinSize="x:480 y:320"/>
|
||||
<Label Text="This is a window!">
|
||||
<att.Font>fontFamily:{Segoe UI} size:32 antialias:true</att.Font>
|
||||
</Label>
|
||||
<Table CellPadding="5" MinSizeLimitation="LimitToElementAndChildren" AlignmentToParent="left:0 top:0 right:0 bottom:0">
|
||||
<att.Rows>
|
||||
<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>
|
||||
</Instance>
|
||||
</Instance>
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace demo
|
||||
|
||||
// #endregion CLASS_MEMBER_GUIEVENT_HANDLER
|
||||
|
||||
MainWindow::MainWindow()
|
||||
MainWindow::MainWindow(Ptr<demo::IViewModel> 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<demo::IViewModel>), { 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)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,30 +15,48 @@ DO NOT MODIFY
|
||||
|
||||
namespace demo
|
||||
{
|
||||
class IViewModel;
|
||||
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>
|
||||
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>;
|
||||
private:
|
||||
Ptr<demo::IViewModel> ViewModel_;
|
||||
protected:
|
||||
vl::presentation::controls::GuiSinglelineTextBox* textBoxName;
|
||||
|
||||
void InitializeComponents()
|
||||
void InitializeComponents(Ptr<demo::IViewModel> ViewModel)
|
||||
{
|
||||
ViewModel_ = ViewModel;
|
||||
if (InitializeFromResource())
|
||||
{
|
||||
GUI_INSTANCE_REFERENCE(textBoxName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewModel_ = 0;
|
||||
}
|
||||
}
|
||||
public:
|
||||
MainWindow_()
|
||||
:vl::presentation::GuiInstancePartialClass<vl::presentation::controls::GuiWindow>(L"demo::MainWindow")
|
||||
,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
|
||||
{
|
||||
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<demo::IViewModel> ViewModel);
|
||||
~MainWindow();
|
||||
};
|
||||
}
|
||||
|
||||
Binary file not shown.
+5
-5
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user