Converters

There are seven converters included so far:
  • UnHtmlConverter: Removes Html Tags to show a simple version of some HTML content.
  • StringCaseConverter: Allows you to upper or lower case a data binding.
  • DateTimeConverter: Converts DateTime values to and from strings.
  • MoneyConverter: Culture relative conversion from double/decimal to money.
  • VisibilityConverter: Boolean to Visibility.
  • NullVisibilityConverter: From null/non-null to Visibility.
  • StringFormatConverter: Performs a one-way string conversion.

UnHtmlConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:UnHtmlConverter x:Key="unHtmlCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- Remove HTML Tags -->
    <TextBlock Text="{Binding SomeHtml, Converter={StaticResource unHtmlCvt}}" />
  </Grid>
</phone:PhoneApplicationPage>

StringCaseConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:StringCaseConverter x:Key="stringCaseCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- To Lower Case -->
    <TextBlock Text="{Binding SomeText, Converter={StaticResource stringCaseCvt}}" />
    <!-- To Upper Case -->
    <TextBlock Text="{Binding SomeText, Converter={StaticResource stringCaseCvt}, ConverterParameter=u}" />
  </Grid>
</phone:PhoneApplicationPage>

DateTimeConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:DateTimeValueConverter x:Key="dateTimeCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- DateTimeConverter -->
    <TextBlock FontWeight="Bold"
                Text="DateTimeConverter" />
    <TextBlock Text="{Binding SomeDate, 
                              Converter={StaticResource dateTimeCvt}, 
                              ConverterParameter=d}" />
  </Grid>
</phone:PhoneApplicationPage>

MoneyConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:MoneyConverter x:Key="moneyCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- MoneyConverter -->
    <TextBlock FontWeight="Bold"
                Text="MoneyConverter" />
    <TextBlock Text="{Binding SomeMoney, 
                              Converter={StaticResource moneyCvt}}" />
  </Grid>
</phone:PhoneApplicationPage>


VisibilityConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:VisibilityConverter x:Key="visCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- VisibilityConverter -->
    <TextBlock FontWeight="Bold"
                Text="VisibiltyConverter" />
    <TextBlock Text="If You Can See This, it worked!"
                Visibility="{Binding Visibility, 
                                    Converter={StaticResource visCvt}}" />
  </Grid>
</phone:PhoneApplicationPage>


NullVisibilityConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:NullVisibilityConverter x:Key="nullVisibilityCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- NullVisibilityConverter -->
    <TextBlock FontWeight="Bold"
                Text="NullVisibiltyConverter" />
    <TextBlock Text="If You Can See This, it worked!"
                Visibility="{Binding SomeNull, 
                                    Converter={StaticResource nullVisibilityCvt}, 
                                    ConverterParameter=false}" />
  </Grid>
</phone:PhoneApplicationPage>


StringFormatConverter:

<phone:PhoneApplicationPage ...>
  <phone:PhoneApplicationPage.Resources>
    <cvt:StringFormatConverter x:Key="formatCvt" />
  </phone:PhoneApplicationPage.Resources>
  <!--LayoutRoot is the root grid where all page content is placed-->
  <Grid x:Name="LayoutRoot"
        Background="Transparent">
    <!-- StringFormatConverter -->
    <TextBlock FontWeight="Bold"
                Text="StringFormatConverter" />
    <TextBlock Text="{Binding SomeDouble,
                              Converter={StaticResource formatCvt}, 
                              ConverterParameter='00.00'}" />
  </Grid>
</phone:PhoneApplicationPage>

Last edited Mar 5, 2011 at 7:46 AM by TheADOGuy, version 3

Comments

No comments yet.