|
2 | 2 |
|
3 | 3 | public partial class LinearGradientBlurPanel : Grid |
4 | 4 | { |
| 5 | + private CompositionRoundedRectangleGeometry clipGeometry; |
5 | 6 | public LinearGradientBlurPanel() |
6 | 7 | { |
7 | 8 | HorizontalAlignment = HorizontalAlignment.Stretch; |
8 | 9 | VerticalAlignment = VerticalAlignment.Stretch; |
9 | 10 |
|
| 11 | + SizeChanged += OnSizeChanged; |
10 | 12 | this.Loaded += OnLoaded; |
11 | 13 | } |
12 | 14 |
|
@@ -56,14 +58,43 @@ private LinearGradientBlurHelper EnsureHelper() |
56 | 58 | StartPoint = StartPoint.ToVector2(), |
57 | 59 | EndPoint = EndPoint.ToVector2(), |
58 | 60 | }; |
| 61 | + |
| 62 | + clipGeometry = compositor.CreateRoundedRectangleGeometry(); |
| 63 | + |
| 64 | + var clip = compositor.CreateGeometricClip(); |
| 65 | + clip.Geometry = clipGeometry; |
| 66 | + |
| 67 | + helper.RootVisual.Clip = clip; |
| 68 | + |
| 69 | + UpdateClipSize(); |
| 70 | + UpdateCornerRadius(); |
| 71 | + |
59 | 72 | ElementCompositionPreview.SetElementChildVisual(this, helper.RootVisual); |
60 | 73 | } |
61 | 74 | } |
62 | 75 | } |
63 | 76 |
|
64 | 77 | return helper; |
65 | 78 | } |
| 79 | + private void UpdateClipSize() |
| 80 | + { |
| 81 | + if (clipGeometry != null) |
| 82 | + { |
| 83 | + clipGeometry.Size = new Vector2((float)ActualWidth, (float)ActualHeight); |
| 84 | + } |
| 85 | + } |
| 86 | + private void OnSizeChanged(object sender, SizeChangedEventArgs e) |
| 87 | + { |
| 88 | + UpdateClipSize(); |
| 89 | + } |
66 | 90 |
|
| 91 | + private void UpdateCornerRadius() |
| 92 | + { |
| 93 | + if (clipGeometry != null) |
| 94 | + { |
| 95 | + clipGeometry.CornerRadius = new Vector2((float)CornerRadius); |
| 96 | + } |
| 97 | + } |
67 | 98 | public double MaxBlurAmount |
68 | 99 | { |
69 | 100 | get { return (double)GetValue(MaxBlurAmountProperty); } |
@@ -109,6 +140,24 @@ public Point EndPoint |
109 | 140 | public static readonly DependencyProperty EndPointProperty = |
110 | 141 | DependencyProperty.Register(nameof(EndPoint), typeof(Point), typeof(LinearGradientBlurPanel), new PropertyMetadata(new Point(0, 1), OnDependencyPropertyChanged)); |
111 | 142 |
|
| 143 | + public new double CornerRadius |
| 144 | + { |
| 145 | + get { return (double)GetValue(CornerRadiusProperty); } |
| 146 | + set { SetValue(CornerRadiusProperty, value); } |
| 147 | + } |
| 148 | + |
| 149 | + public static new readonly DependencyProperty CornerRadiusProperty = |
| 150 | + DependencyProperty.Register(nameof(CornerRadius), typeof(double), typeof(LinearGradientBlurPanel), new PropertyMetadata(default(double), OnCornerRadiusChanged)); |
| 151 | + |
| 152 | + private static void OnCornerRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
| 153 | + { |
| 154 | + var ctl = (LinearGradientBlurPanel)d; |
| 155 | + if (ctl != null) |
| 156 | + { |
| 157 | + ctl.UpdateCornerRadius(); |
| 158 | + } |
| 159 | + } |
| 160 | + |
112 | 161 | public void StartMaxBlurAmountAnimation(CompositionAnimation animation) => StartHelperCompositionAnimation("MaxBlurAmount", animation); |
113 | 162 | public void StopMaxBlurAmountAnimation() => StopHelperCompositionAnimation("MaxBlurAmount"); |
114 | 163 |
|
|
0 commit comments