-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathBooleanToVisibility.cs
More file actions
38 lines (35 loc) · 929 Bytes
/
BooleanToVisibility.cs
File metadata and controls
38 lines (35 loc) · 929 Bytes
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
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace Waher.IoTGateway.Setup.Windows
{
/// <summary>
/// Converts boolean values to and from <see cref="Visibility"/> values.
/// </summary>
public class BooleanToVisibility : MarkupExtension, IValueConverter
{
/// <inheritdoc/>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool b)
return b ? Visibility.Visible : Visibility.Collapsed;
else
return Visibility.Collapsed;
}
/// <inheritdoc/>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Visibility v)
return v == Visibility.Visible;
else
return false;
}
/// <inheritdoc/>
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}