ManagedFileChooserConverters.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using Avalonia;
  5. using Avalonia.Controls;
  6. using Avalonia.Controls.Primitives;
  7. using Avalonia.Data.Converters;
  8. using Avalonia.Layout;
  9. using Avalonia.Markup.Xaml.MarkupExtensions;
  10. using Avalonia.Media;
  11. using SukiUI.Content;
  12. namespace SukiUI.Theme
  13. {
  14. public class TextToPathConverter : IValueConverter
  15. {
  16. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  17. {
  18. var pathes = (value as string).Split('\\');
  19. if (pathes.Length > 3)
  20. {
  21. pathes = pathes.Skip(1).ToArray();
  22. }
  23. var stackPanel = new StackPanel
  24. {
  25. VerticalAlignment = VerticalAlignment.Center, Orientation = Orientation.Horizontal,
  26. Margin = new Thickness(5)
  27. };
  28. for (var i = 0; i < pathes.Length; i++)
  29. {
  30. var t = new TextBlock
  31. {
  32. Text = pathes[i],
  33. FontWeight =
  34. Application.Current!.TryGetResource("DefaultDemiBold", Application.Current!.ActualThemeVariant,
  35. out var fontWeight)
  36. ? (FontWeight)fontWeight!
  37. : FontWeight.DemiBold,
  38. FontSize = 14, VerticalAlignment = VerticalAlignment.Center,
  39. [!TextBlock.ForegroundProperty] = i == pathes.Length - 1
  40. ? new DynamicResourceExtension("SukiText")
  41. : new DynamicResourceExtension("SukiLowText")
  42. };
  43. stackPanel.Children.Add(t);
  44. var p = new PathIcon
  45. {
  46. Height = 6, Margin = new Thickness(12, 4, 12, 2), Width = 5, Data = Icons.ChevronRight,
  47. IsVisible = i != pathes.Length - 1, VerticalAlignment = VerticalAlignment.Center,
  48. Classes = { "Flippable" }
  49. };
  50. p[!TemplatedControl.ForegroundProperty] = new DynamicResourceExtension("SukiLowText");
  51. stackPanel.Children.Add(p);
  52. }
  53. return stackPanel;
  54. }
  55. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  56. {
  57. throw new NotSupportedException();
  58. }
  59. }
  60. public class WindowManagedConverter : IValueConverter
  61. {
  62. public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
  63. {
  64. var w = value as Window;
  65. w.SystemDecorations = SystemDecorations.BorderOnly;
  66. // w.ExtendClientAreaToDecorationsHint = true;
  67. return "";
  68. }
  69. public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
  70. {
  71. throw new NotSupportedException();
  72. }
  73. }
  74. }