title: wp7 Date Formatting during Binding
body: <p>I tried following the following example with no luck:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter%28v=VS.95%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter%28v=VS.95%29.aspx</a></p>
  
  <p>I also tried to follow this as well:</p>
  
  <p><a href="https://stackoverflow.com/questions/4695057/formatting-a-date-in-xaml-on-wp7">Formatting a date in XAML on WP7</a></p>
  
  <p>I can't get it to work.  When I try to add a reference such as:</p>
  
  <pre><code>&lt;namespace:dateTimeConverter x:Key="MyDateTimeToStringConverter"/&gt;
  </code></pre>
  
  <p><strong>or</strong></p>
  
  <pre><code>&lt;src:DateConverter x:Key="dateConverter"/&gt;
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong.  Any assistance is appreciated!</p>
  
  <p><strong>Here is my class code:</strong></p>
  
  <pre><code>using System;
  using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Ink;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Animation;
  using System.Windows.Shapes;
  using System.Windows.Data;
  using System.Globalization;
  
  namespace OilChangeApplication
  {
  
      public class dateTimeConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
          {
              DateTime date = (DateTime)value;
              return date.ToShortDateString();
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
          {
              string strValue = value as string;
              DateTime resultDateTime;
              if (DateTime.TryParse(strValue, out resultDateTime))
              {
                  return resultDateTime;
              }
              return DependencyProperty.UnsetValue;
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Here is my windows phone form xaml:</strong></p>
  
  <pre><code> &lt;phone:PhoneApplicationPage 
      x:Class="OilChangeApplication.historyInfo"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
      xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      FontFamily="{StaticResource PhoneFontFamilyNormal}"
      FontSize="{StaticResource PhoneFontSizeNormal}"
      Foreground="{StaticResource PhoneForegroundBrush}"
      SupportedOrientations="Portrait" Orientation="Portrait"
      mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
      shell:SystemTray.IsVisible="True"&gt;
  
  
      &lt;!--LayoutRoot is the root grid where all page content is placed--&gt;
      &lt;Grid x:Name="LayoutRoot" Background="Transparent"&gt;
          &lt;Grid.Resources&gt;
  
          &lt;/Grid.Resources&gt;
  
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="*"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
  
  
              &lt;!--TitlePanel contains the name of the application and page title--&gt;
          &lt;StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"&gt;
              &lt;TextBlock x:Name="ApplicationTitle" Text="Change your Oil Application 2.0" Style="{StaticResource PhoneTextNormalStyle}"/&gt;
              &lt;TextBlock x:Name="PageTitle" Text="history" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/&gt;
          &lt;/StackPanel&gt;
  
  
  
          &lt;ListBox Grid.Row="1"&gt;
              &lt;Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"&gt;
  
  
                  &lt;ListBox Height="601" HorizontalAlignment="Left" Margin="-3,2,0,0" Name="lbHistory" VerticalAlignment="Top" Width="460" ItemsSource="{Binding historyItemsCollection}"&gt;
  
                      &lt;ListBox.ItemTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal"&gt;
                                  &lt;TextBlock FontFamily="Segoe WP Semibold" FontWeight="Bold" FontSize="30" VerticalAlignment="Top" Margin="20,10"&gt;*&lt;/TextBlock&gt;
                                  &lt;StackPanel&gt;
                                      &lt;TextBlock x:Name="ItemText" Text="{Binding VehicleName}" FontSize="{StaticResource PhoneFontSizeLarge}"/&gt;
                                      &lt;StackPanel Orientation="Horizontal"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"&gt;
                                              &lt;!--&lt;TextBlock x:Name="ocDate" Text="{Binding OilChangedDate}"&gt;&lt;/TextBlock&gt;--&gt;
                                          &lt;TextBlock Text="{Binding OilChangedDate, Converter={StaticResource dateTimeConverter},ConverterParameter=\{0:M\}}" /&gt;
                                          &lt;TextBlock x:Name="ocOdometer" Text="{Binding OilChangedOdometer}" FontSize="{StaticResource PhoneFontSizeNormal}"/&gt;
                                          &lt;/StackPanel&gt;
                                  &lt;/StackPanel&gt;
                              &lt;/StackPanel&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/ListBox.ItemTemplate&gt;
  
                  &lt;/ListBox&gt;
              &lt;/Grid&gt;
          &lt;/ListBox&gt;
      &lt;/Grid&gt;
  
  
      &lt;!--Sample code showing usage of ApplicationBar--&gt;
      &lt;phone:PhoneApplicationPage.ApplicationBar&gt;
          &lt;shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"&gt;
              &lt;shell:ApplicationBarIconButton IconUri="/Images/check.png" Text="save" x:Name="btnSave" Click="btnSave_Click"/&gt;
              &lt;shell:ApplicationBarIconButton IconUri="/Images/cancel.png" Text="cancel" x:Name="btnCancel" Click="btnCancel_Click"/&gt;
          &lt;/shell:ApplicationBar&gt;
      &lt;/phone:PhoneApplicationPage.ApplicationBar&gt;
  
  &lt;/phone:PhoneApplicationPage&gt;
  </code></pre>