- validizor_src.zip
- validizor_src
- MyBusinessObjects
- Validize
- ValidizorExample.sln
- ValidizorExample
- WPFSamples - 2007-01-11
- Library
- BlockBar
- ColorPicker
- DatePicker
- Graph
- InfoTextBox
- ListPager
- MonthCalendar
- NumericUpDown
- Properties
- themes
- TreeViewHelperClasses
- WPFSamplesLib.csproj
- Zap
- validizor_demo.zip
- validizor_demo
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Validation.dll
- Microsoft.Practices.ObjectBuilder.dll
- MyBusinessObjects.dll
- Validize.dll
- ValidizorExample.exe
- WPFSamplesLib.dll
|
//---------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Globalization;
using System.Windows.Data;
namespace Microsoft.Samples.KMoore.WPFSamples.DateControls
{
/// <summary>
/// Convert between DateTime and string, it's the default Converter for DatePicker.DateValueConverter
/// </summary>
public sealed class DateTimeValueConverter : IValueConverter
{
/// <summary>
/// Convert DateTime to a formatted string(ShortDatePattern)
/// </summary>
/// <param name="value">DateTime</param>
/// <param name="targetType">string</param>
/// <param name="parameter">null</param>
/// <param name="culture"></param>
/// <returns>formatted or empty string</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (culture == null)
{
throw new ArgumentNullException("culture");
}
DateTimeFormatInfo dateTimeFormat = culture.DateTimeFormat;
if (dateTimeFormat == null)
{
throw new ArgumentNullException("culture.DateTimeFormat");
}
if (value != null && value is DateTime)
{
DateTime date = (DateTime)value;
return date.ToString(dateTimeFormat.ShortDatePattern, dateTimeFormat);
}
else
{
return string.Empty;
}
}
/// <summary>
/// Convert input string to DateTime
/// </summary>
/// <param name="value">string</param>
/// <param name="targetType">DateTime</param>
/// <param name="parameter">null</param>
/// <param name="culture"></param>
/// <returns>DateTime or null</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (culture == null)
{
throw new ArgumentNullException("culture");
}
if (value != null && value is string)
{
return DateTime.Parse((string)value, culture.DateTimeFormat);
}
else
{
return null;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.