26 lines
914 B
C#
26 lines
914 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace UtopiaCanteenSystem.Converters
|
|
{
|
|
public class StringLengthToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
// Binding is typically Text.Length (int): show watermark when empty (0), hide when has text
|
|
if (value is int length)
|
|
return length == 0 ? Visibility.Visible : Visibility.Collapsed;
|
|
if (value is string s)
|
|
return string.IsNullOrEmpty(s) ? Visibility.Visible : Visibility.Collapsed;
|
|
return Visibility.Visible;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return Binding.DoNothing; // No reverse conversion
|
|
}
|
|
}
|
|
}
|