Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Programming Guide
Defining a UI
 Setting UI Properties
Setting UI Properties

The Properties attribute of a UI allows you to parameterize a UI with properties, each of which consists of a type, a name, and a default value, thus allowing you to customize the UI. A property can be any MCML or user-defined type. Property default values are shared among all instances of the UI. These values are public and can be overridden. In the following example, the Properties attribute defines default values for the Color and Font attributes of a Text element:

<Mcml xmlns="http://schemas.microsoft.com/2006/mcml" >
  <UI Name="UsingProperties">
    <Properties>
      <Color Name="Foreground" Color="Blue"/>
      <Font Name="DocFont" Font="Verdana,22" />
    </Properties>

    <Content>
      <Text Content="Using Font and Color properties" Font="[DocFont]" Color="[Foreground]"/>
    </Content>
  </UI>
</Mcml>

You can require the parent UI to supply a value for any property by marking it as "$Required", and an error will occur if that property is not specified. The following example requires the parent UI to define a Label string:

<Mcml
    xmlns="http://schemas.microsoft.com/2006/mcml"
    xmlns:cor="assembly://MsCorLib/System"
    xmlns:me="Me">

  <UI Name="MainDisplay" BaseUI="me:LabelProperties">
    <Content>
      <Panel Layout="VerticalFlow">
        <Children>
          <me:LabelProperties Label="A 'Label' string is required." />
          <me:LabelProperties Label="If 'Label' is not specified, an error occurs." />
        </Children>
      </Panel>
    </Content>
  </UI>

  <UI Name="LabelProperties">
    <Properties>
      <!-- This property requires you to specify a string for 'Label' when referencing this UI. -->
      <cor:String Name="Label" String="$Required"/>
      <Color Name="ForeColor" Color="Red"/>
    </Properties>

    <Content>
      <Text Name="Display" Content="[Label]" Color="[ForeColor]" Font="Arial,20" />
    </Content>
  </UI>
</Mcml>

Note   Only reference types (such as classes) can be marked as $Required. Value types, such as structures or types, cannot be marked as $Required.

Any property that you define in the Properties block is saved when you navigate away from the page. When returning to the page, these properties are restored.

See Also

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker