Export (0) Print
Expand All
Expand Minimize

FormatTransformer Element

Converts an object to a string with a specified format.

Syntax

<FormatTransformer
    ExtendedFormat="string"
    Format="string"
    ToLower="{true | false}"
    ToUpper="{true | false}"
/>

Attributes

ExtendedFormat

Contains the extended format string.

Format

Contains the format string. This string must contain a "{0}" to denote the location of the string representation.

ToLower

Indicates whether to convert the result to lower case.

ToUpper

Indicates whether to convert the result to upper case.

Remarks

The FormatTransformer element supports extended formatting on objects that implement IFormattable.

For more information about extended format strings, see the Remarks section of the String.Format Method on the MSDN web site.

The target of the FormatTransformer must accept a string.

You cannot perform one conversion after another on the same variable in a chain. To perform multiple conversions, you can transform the value to an intermediate local and then bind that value to your target using another transformer, or use multiple actions on the same variable using a rule.

Example Code

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

  <UI Name="FormatTransformer">

    <Locals>
      <cor:Double Name="PhoneNumber" Double="4255551212"/>
    </Locals>

    <Rules>
      <!-- The target is Content on a Text element, which expects a string. -->
      <Binding Source="[PhoneNumber]" Target="[Label.Content]">
        <Transformer>
          <FormatTransformer Format="The phone number is {0}."  ExtendedFormat="(###) ###-####"/>
        </Transformer>
      </Binding>
    </Rules>

    <Content>
      <Text Name="Label" Color="Orchid" Font="Verdana,30"/>
    </Content>

  </UI>
</Mcml>

Requirements

Platform: Windows Vista Ultimate, Windows Vista Home Premium, and later

See Also

Show:
© 2014 Microsoft