Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Within SL4 this is possible...</p> <pre><code>&lt;TextBlock Text="{Binding Date, StringFormat='MM/dd/yyyy'}}"/&gt; </code></pre> <p>...within SL3 you would need to make use of an <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(v=VS.95).aspx" rel="noreferrer">IValueConverter</a>.</p> <pre><code>public class DateTimeToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return String.Format("{0:MM/dd/yyyy}", (DateTime)value); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>If you wanted a more robust approach you could make use of the <code>ConverterParameter</code>.</p> <pre><code> public class DateTimeToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (parameter == null) return ((DateTime)value).ToString(culture); else return ((DateTime)value).ToString(parameter as string, culture); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>Then in your XAML you would first define the converter as a resource...</p> <pre><code>&lt;namespace:DateTimeToStringConverter x:Key="MyDateTimeToStringConverter"/&gt; </code></pre> <p>..then reference it along with an acceptable parameter for formatting the <code>DateTime</code> value...</p> <pre><code>&lt;TextBlock Text="{Binding Date, Converter={StaticResource MyDateTimeToStringConverter}, ConverterParameter=\{0:M\}}"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload