Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: DataGridControl - Formatting Auto-Generated DateTime? Column

$
0
0
Hi,

Your second option almost works. Here's how I would use it :
Use a column with a CellContentTemplate :
<xcdg:Column FieldName="OrderDate"
                             Title="Order Date"
                             Width="120"
                             CellContentTemplate="{StaticResource DateDataTemplate}" />
The DataTemplate would use a DateConverter :
<view:DisplayedValueConverter x:Key="DisplayedValueConverter" />

  <DataTemplate x:Key="DateDataTemplate">
      <TextBlock Text="{Binding Converter={StaticResource DisplayedValueConverter} }" />
    </DataTemplate>
And the DateConverter would use the DateTime.ToString() method to convert the date :
 public class DisplayedValueConverter : IValueConverter
  {
    #region IValueConverter Members
    
    public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
    {
      if( value == null )
        return null;

      System.DateTime dateTime = ( System.DateTime )value;
      return dateTime.ToString( "ddd MM/ dd / yy hh:mm tt" );
    }

    public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
    {
      throw new NotImplementedException();
    }

    #endregion
  }
――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF

Viewing all articles
Browse latest Browse all 4964

Trending Articles