using System; using System.Globalization; using System.Windows; using System.Windows.Data; using System.Windows.Markup; namespace AIPractice.LabellerServer.WPF { [MarkupExtensionReturnType(typeof(IValueConverter))] public class BoolToVisibleConverter : MarkupExtension, IValueConverter { public static BoolToVisibleConverter Converter { get; private set; } static BoolToVisibleConverter() { Converter = new BoolToVisibleConverter(); } public override object ProvideValue(IServiceProvider serviceProvider) { return Converter ?? (Converter = new BoolToVisibleConverter()); } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { var b = (bool)value; return b ? Visibility.Visible : Visibility.Collapsed; } return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } [MarkupExtensionReturnType(typeof(IValueConverter))] public class LabelNameConverter : MarkupExtension, IValueConverter { public static LabelNameConverter Converter { get; private set; } static LabelNameConverter() { Converter = new LabelNameConverter(); } public override object ProvideValue(IServiceProvider serviceProvider) { return Converter ?? (Converter = new LabelNameConverter()); } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null) { var name = (string)value; return string.IsNullOrEmpty(name) ? "默认标签" : name; } return "默认标签"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }