BGSettingUtil.cs 2.2 KB

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