-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInverseBooleanConverter.cs
43 lines (41 loc) · 1.7 KB
/
InverseBooleanConverter.cs
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
34
35
36
37
38
39
40
41
42
43
using System;
using System.Globalization;
using System.Windows.Data;
namespace Sharp.Utils.Wpf
{
/// <summary>
/// Converts a boolean value to its inverse.
/// </summary>
[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBooleanConverter : IValueConverter
{
/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>The converted value.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is bool))
throw new ArgumentException("value must be a boolean.", "value");
return !(bool)value;
}
/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">The type to convert to.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>The converted value.</returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is bool))
throw new ArgumentException("value must be a boolean.", "value");
return !(bool)value;
}
}
}