PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/V2.2/trunk/Quickstarts/Commanding/Desktop/Commanding.OrderModule/Converter/DateConverter.cs

#
C# | 43 lines | 24 code | 3 blank | 16 comment | 1 complexity | 97a753bb9dc82434f5f175f7c1857362 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System;
  18. using System.Globalization;
  19. using System.Windows.Data;
  20. namespace Commanding.Modules.Order.Converter
  21. {
  22. public class DateConverter : IValueConverter
  23. {
  24. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  25. {
  26. DateTime date = (DateTime)value;
  27. return date.ToString("d", culture);
  28. }
  29. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  30. {
  31. string strValue = value.ToString();
  32. DateTime resultDateTime;
  33. if (DateTime.TryParse(strValue, culture, DateTimeStyles.None, out resultDateTime))
  34. {
  35. return resultDateTime;
  36. }
  37. return value;
  38. }
  39. }
  40. }