Click or drag to resize

Scope

A Scope is a concept that allows multiple elements of a lab to have same Id, as long as these elements are located in different scopes.

Example
                  <
                  Element Id="Incubator1" IsScope="True">
  <Fields>
    <Field Id="Incubator_IsOpen" Value="False" Type="bool">
      <ChangedHandler>
        <CompositeAction>
          ...
        </CompositeAction>
      </ChangedHandler>
    </Field>
  </Fields>
  <MessageHandlers>
    <MessageHandler Message="Open">
      <Actions>
        <SetField FieldId="Incubator_IsOpen" Value="True" />
      </Actions>
    </MessageHandler>
  </MessageHandlers>  
  <Elements>
    <Placeholder Id="Placeholder1" IsClickable="{FieldValue FieldId=Incubator_IsOpen}" />
  </Elements>
</Element>
IsScope attribute

Setting IsScope="True" on element makes all of its child objects no longer accessible by Id from outside. This also means that element can be replicated multiple times in one scene without causing Id conflicts.

Example
                  <
                  Element Id="Incubator1" IsScope="True">
  <Fields>
    <Field Id="Incubator_IsOpen" Value="False" Type="bool">
      <ChangedHandler>
        <CompositeAction>
          ...
        </CompositeAction>
      </ChangedHandler>
    </Field>
  </Fields>
  <MessageHandlers>
    <MessageHandler Message="Open">
      <Actions>
        <SetField FieldId="Incubator_IsOpen" Value="True" />
      </Actions>
    </MessageHandler>
  </MessageHandlers>  
  <Elements>
    <Placeholder Id="Placeholder1" IsClickable="{FieldValue FieldId=Incubator_IsOpen}" />
  </Elements>
</Element>

<Element Id="Incubator2" IsScope="True">
  <Fields>
    <Field Id="Incubator_IsOpen" Value="False" Type="bool">
      <ChangedHandler>
        <CompositeAction>
          ...
        </CompositeAction>
      </ChangedHandler>
    </Field>
  </Fields>
  <MessageHandlers>
    <MessageHandler Message="Open">
      <Actions>
        <SetField FieldId="Incubator_IsOpen" Value="True" />
      </Actions>
    </MessageHandler>
  </MessageHandlers>  
  <Elements>
    <Placeholder Id="Placeholder1" IsClickable="{FieldValue FieldId=Incubator_IsOpen}" />
  </Elements>
</Element>

Two incubators are defined alongside each other, with Ids specified on child elements.

Fields and scope

Fields can be used to pass values in and out of scope. SetField and FieldValue should have Scope attribute/parameter defined.

Example
                  <
                  SetField FieldId="Incubator_IsOpen" Scope="{Binding ElementId=Incubator1}" Value="True" />
Example
                  <
                  Button IsVisible="{FieldValue Incubator_IsOpen, Scope={Binding ElementId=Incubator1}" />

Notice the absense of Scope attribute/parameter on SetField and FieldValue in previous examples.

Messages and scope

Messages is another way to communicate with elements hidden behind a scope boundary. Actions inside of a MessageHandler can directly interact with elements, and message handler can be invoked from outside using SendMessage action.

Example
                  <
                  SendMessage Message"Open" Target="{Binding ElementId=Incubator1}" />