BooleanToEnabledDisabledConverter.cs 920 B

123456789101112131415161718192021222324252627282930
  1. namespace GDNXFD.Alert.Config.Converters
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Data;
  11. public class BooleanToEnabledDisabledConverter : IValueConverter
  12. {
  13. private const string EnabledText = "启用";
  14. private const string DisabledText = "停用";
  15. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. return Equals(true, value)
  18. ? EnabledText
  19. : DisabledText;
  20. }
  21. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  22. {
  23. //Actually won't be used, but in case you need that
  24. return Equals(value, EnabledText);
  25. }
  26. }
  27. }