-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStringToVisibilityConverter.cs
More file actions
40 lines (34 loc) · 1.02 KB
/
StringToVisibilityConverter.cs
File metadata and controls
40 lines (34 loc) · 1.02 KB
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
namespace Menees.Windows.Presentation
{
#region Using Directives
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
#endregion
/// <summary>
/// Converts null, empty, or non-empty string values into Visibility values.
/// </summary>
public class StringToVisibilityConverter : IValueConverter
{
#region Public Methods
/// <summary>
/// Converts a string value (null, empty, or non-empty) into a Visibility.
/// </summary>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string? text = value as string;
Visibility result = string.IsNullOrEmpty(text) ? Visibility.Collapsed : Visibility.Visible;
return result;
}
/// <summary>
/// Returns UnsetValue.
/// </summary>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => DependencyProperty.UnsetValue;
#endregion
}
}