BGSettingUtil.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using GeekDesk.Constant;
  2. using GeekDesk.ViewModel;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Media;
  7. using System.Windows.Media.Effects;
  8. namespace GeekDesk.Util
  9. {
  10. public class BGSettingUtil
  11. {
  12. private static readonly AppConfig appConfig = MainWindow.appData.AppConfig;
  13. public static void BGSetting()
  14. {
  15. if (appConfig.BGStyle == BGStyle.ImgBac || appConfig.BGStyle == 0)
  16. {
  17. Image image = new Image
  18. {
  19. Effect = new BlurEffect()
  20. {
  21. Radius = appConfig.BlurValue
  22. },
  23. Margin = new Thickness(-30),
  24. Source = appConfig.BitmapImage,
  25. Opacity = (double)(Math.Round((decimal)(appConfig.BgOpacity / 100.00), 2))
  26. };
  27. //binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  28. //image.SetBinding(Image.OpacityProperty, binding);
  29. Grid grid = new Grid
  30. {
  31. ClipToBounds = true
  32. };
  33. grid.Children.Add(image);
  34. VisualBrush vb = new VisualBrush
  35. {
  36. Visual = grid
  37. };
  38. MainWindow.mainWindow.BGBorder.Background = vb;
  39. }
  40. else
  41. {
  42. LinearGradientBrush lgb = new LinearGradientBrush();
  43. GradientStop gs = new GradientStop
  44. {
  45. Color = (Color)ColorConverter.ConvertFromString(appConfig.GradientBGParam.Color1),
  46. Offset = 0
  47. };
  48. lgb.GradientStops.Add(gs);
  49. GradientStop gs2 = new GradientStop
  50. {
  51. Color = (Color)ColorConverter.ConvertFromString(appConfig.GradientBGParam.Color2),
  52. Offset = 1
  53. };
  54. lgb.GradientStops.Add(gs2);
  55. lgb.Opacity = (double)(Math.Round((decimal)(appConfig.BgOpacity / 100.00), 2));
  56. MainWindow.mainWindow.BGBorder.Background = lgb;
  57. }
  58. }
  59. }
  60. }