Skip to content

Instantly share code, notes, and snippets.

@vczh
Created April 3, 2016 11:23
Show Gist options
  • Save vczh/9bfcb25cfdf73e0f4eff4b79e84926be to your computer and use it in GitHub Desktop.
Save vczh/9bfcb25cfdf73e0f4eff4b79e84926be to your computer and use it in GitHub Desktop.
Dynamic Window (xml)
<Resource>
<Script name="ViewModelScript">
<Workflow-ViewModel>
<![CDATA[
module script;
interface IViewModel
{
func GetX() : int;
func SetX(value : int) : void;
prop X : int {GetX, SetX}
func GetY() : int;
func SetY(value : int) : void;
prop Y : int {GetY, SetY}
func GetZ() : int;
event ZChanged();
prop Z : int {GetZ}
}
]]>
</Workflow-ViewModel>
</Script>
<Script name="SharedScript">
<Workflow>
<![CDATA[
module script;
class ViewModelBuilder
{
static func Build() : IViewModel^
{
return new IViewModel^
{
var x = 0;
var y = 0;
override func GetX() : int { return x; }
override func SetX(value : int) : void { if (x != value) { x = value; ZChanged(); } }
override func GetY() : int { return y; }
override func SetY(value : int) : void { if (y != value) { y = value; ZChanged(); } }
override func GetZ() : int { return x + y; }
};
}
}
]]>
</Workflow>
</Script>
<Instance name="MainWindowResource">
<Instance ref.Class="demo::MainWindow">
<ref.Parameter Name="ViewModel" Class="IViewModel"/>
<Window Text="MainWindow" ClientSize="x:480 y:320">
<att.ViewModel-set X-bind="(cast int textBoxA.Text) ?? 0" Y-bind="(cast int textBoxB.Text) ?? 0"/>
<att.BoundsComposition-set PreferredMinSize="x:480 y:320"/>
<Table CellPadding="5" AlignmentToParent="left:0 top:0 right:0 bottom:0" MinSizeLimitation="LimitToElementAndChildren">
<att.Rows>
<CellOption>composeType:MinSize</CellOption>
<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:200</CellOption>
<CellOption>composeType:Percentage percentage:1.0</CellOption>
</att.Columns>
<Cell Site="row:0 column:0">
<Label Text="A ="/>
</Cell>
<Cell Site="row:0 column:1">
<SinglelineTextBox ref.Name="textBoxA" Text="1">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0" PreferredMinSize="y:24"/>
</SinglelineTextBox>
</Cell>
<Cell Site="row:1 column:0">
<Label Text="B ="/>
</Cell>
<Cell Site="row:1 column:1">
<SinglelineTextBox ref.Name="textBoxB" Text="2">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0" PreferredMinSize="y:24"/>
</SinglelineTextBox>
</Cell>
<Cell Site="row:2 column:0">
<Label Text="A + B ="/>
</Cell>
<Cell Site="row:2 column:1">
<SinglelineTextBox Text-bind="ViewModel.Z">
<att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0" PreferredMinSize="y:24"/>
</SinglelineTextBox>
</Cell>
</Table>
</Window>
</Instance>
</Instance>
</Resource>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment