You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. namespace BPA.UIControl.Converters
  7. {
  8. /// <summary>
  9. /// ListView 的 GridView Style 选择转换器
  10. /// </summary>
  11. public class ListViewGridViewConverter : IValueConverter
  12. {
  13. /// <summary>
  14. /// 默认 ListView 样式
  15. /// </summary>
  16. public Style DefaultStyle { get; set; }
  17. /// <summary>
  18. /// GridView 样式
  19. /// </summary>
  20. public Style ViewStyle { get; set; }
  21. /// <inheritdoc/>
  22. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  23. {
  24. if (value is ListView listView)
  25. {
  26. return listView.View != null ? ViewStyle : DefaultStyle;
  27. }
  28. return value is ViewBase ? ViewStyle : DefaultStyle;
  29. }
  30. /// <inheritdoc/>
  31. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  32. {
  33. return Binding.DoNothing;
  34. }
  35. }
  36. }