blob: af585a9f6de38438bbb57565532724c06335f9ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
using System;
using System.Globalization;
using System.Windows.Data;
namespace MaterialDesignThemes.Wpf.Converters
{
/// <summary>
/// Help us format the content of a header button in a calendar.
/// </summary>
/// <remarks>
/// Expected items, in the following order:
/// 1) DateTime Calendar.DisplayDate
/// 2) DateTime? Calendar.SelectedDate
/// </remarks>
public class CalendarDateCoalesceConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length != 2) throw new ArgumentException("Unexpected", "values");
if (!(values[0] is DateTime)) throw new ArgumentException("Unexpected", "values");
if (values[1] != null && !(values[1] is DateTime?)) throw new ArgumentException("Unexpected", "values");
var selectedDate = (DateTime?) values[1];
return selectedDate ?? values[0];
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}
|