1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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();
- }
- }
- }
|