Skip to content

Commit 3a9d00d

Browse files
committed
Add CornerRadius in LinearGradientBlurPanel
1 parent 26dda98 commit 3a9d00d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

dev/DevWinUI.Controls/Controls/Win2DAndComposition/LinearGradientBlurPanel/LinearGradientBlurPanel.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
public partial class LinearGradientBlurPanel : Grid
44
{
5+
private CompositionRoundedRectangleGeometry clipGeometry;
56
public LinearGradientBlurPanel()
67
{
78
HorizontalAlignment = HorizontalAlignment.Stretch;
89
VerticalAlignment = VerticalAlignment.Stretch;
910

11+
SizeChanged += OnSizeChanged;
1012
this.Loaded += OnLoaded;
1113
}
1214

@@ -56,14 +58,43 @@ private LinearGradientBlurHelper EnsureHelper()
5658
StartPoint = StartPoint.ToVector2(),
5759
EndPoint = EndPoint.ToVector2(),
5860
};
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+
5972
ElementCompositionPreview.SetElementChildVisual(this, helper.RootVisual);
6073
}
6174
}
6275
}
6376

6477
return helper;
6578
}
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+
}
6690

91+
private void UpdateCornerRadius()
92+
{
93+
if (clipGeometry != null)
94+
{
95+
clipGeometry.CornerRadius = new Vector2((float)CornerRadius);
96+
}
97+
}
6798
public double MaxBlurAmount
6899
{
69100
get { return (double)GetValue(MaxBlurAmountProperty); }
@@ -109,6 +140,24 @@ public Point EndPoint
109140
public static readonly DependencyProperty EndPointProperty =
110141
DependencyProperty.Register(nameof(EndPoint), typeof(Point), typeof(LinearGradientBlurPanel), new PropertyMetadata(new Point(0, 1), OnDependencyPropertyChanged));
111142

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+
112161
public void StartMaxBlurAmountAnimation(CompositionAnimation animation) => StartHelperCompositionAnimation("MaxBlurAmount", animation);
113162
public void StopMaxBlurAmountAnimation() => StopHelperCompositionAnimation("MaxBlurAmount");
114163

0 commit comments

Comments
 (0)