Skip to content

Commit 0789a59

Browse files
authored
Merge pull request #6769 from Youssef1313/issues/6751
fix: Fix linear gradient border not working on Wasm
2 parents 9c06070 + 3f94332 commit 0789a59

File tree

3 files changed

+68
-36
lines changed

3 files changed

+68
-36
lines changed

src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Controls/BorderTests/Border_Tests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Drawing;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
@@ -165,6 +166,24 @@ public void Border_CornerRadius_Clipping()
165166
);
166167
}
167168

169+
[Test]
170+
[AutoRetry]
171+
[ActivePlatforms(Platform.Android, Platform.Browser)] // iOS not working currently. https://github.com/unoplatform/uno/issues/6749
172+
public void Border_LinearGradient()
173+
{
174+
Run("UITests.Windows_UI_Xaml_Controls.BorderTests.Border_LinearGradientBrush");
175+
176+
var textBoxRect = _app.GetPhysicalRect("MyTextBox");
177+
178+
using var screenshot = TakeScreenshot("Screenshot");
179+
180+
// The color near the end is blueish.
181+
ImageAssert.HasColorAt(screenshot, (float)(textBoxRect.CenterX + 0.45 * textBoxRect.Width), textBoxRect.Y, Color.FromArgb(31, 0, 224), tolerance: 20);
182+
183+
// The color near the start is reddish.
184+
ImageAssert.HasColorAt(screenshot, (float)(textBoxRect.CenterX - 0.45 * textBoxRect.Width), textBoxRect.Y, Color.Red, tolerance: 20);
185+
}
186+
168187
private void SetBorderProperty(string borderName, string propertyName, string value)
169188
{
170189
Console.WriteLine($"Setting {borderName}'s {propertyName} to {value}");

src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/BorderTests/Border_LinearGradientBrush.xaml

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,52 @@
99
d:DesignHeight="300"
1010
d:DesignWidth="400">
1111

12-
<Grid>
13-
<Border Margin="3"
14-
Width="150"
15-
Height="100"
16-
CornerRadius="40"
17-
BorderThickness="4"
18-
BorderBrush="Black">
19-
<Border.Background>
20-
<LinearGradientBrush StartPoint="0,0"
21-
EndPoint="1,1">
22-
<GradientStop Color="Yellow"
23-
Offset="0.0" />
24-
<GradientStop Color="Red"
25-
Offset="0.1" />
26-
<GradientStop Color="Blue"
27-
Offset="0.2" />
28-
<GradientStop Color="LimeGreen"
29-
Offset="0.3" />
30-
<GradientStop Color="Blue"
31-
Offset="0.4" />
32-
<GradientStop Color="Red"
33-
Offset="0.5" />
34-
<GradientStop Color="Yellow"
35-
Offset="0.6" />
36-
<GradientStop Color="Red"
37-
Offset="0.7" />
38-
<GradientStop Color="Blue"
39-
Offset="0.8" />
40-
<GradientStop Color="LimeGreen"
41-
Offset="0.9" />
42-
<GradientStop Color="Blue"
43-
Offset="1.0" />
12+
<StackPanel>
13+
<TextBox x:Name="MyTextBox">
14+
<TextBox.BorderBrush>
15+
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
16+
<LinearGradientBrush.GradientStops>
17+
<GradientStop Offset="0.33" Color="Red"/>
18+
<GradientStop Offset="1.0" Color="Blue"/>
19+
</LinearGradientBrush.GradientStops>
4420
</LinearGradientBrush>
45-
</Border.Background>
46-
</Border>
47-
</Grid>
21+
</TextBox.BorderBrush>
22+
</TextBox>
23+
<Grid>
24+
<Border Margin="3"
25+
Width="150"
26+
Height="100"
27+
CornerRadius="40"
28+
BorderThickness="4"
29+
BorderBrush="Black">
30+
<Border.Background>
31+
<LinearGradientBrush StartPoint="0,0"
32+
EndPoint="1,1">
33+
<GradientStop Color="Yellow"
34+
Offset="0.0" />
35+
<GradientStop Color="Red"
36+
Offset="0.1" />
37+
<GradientStop Color="Blue"
38+
Offset="0.2" />
39+
<GradientStop Color="LimeGreen"
40+
Offset="0.3" />
41+
<GradientStop Color="Blue"
42+
Offset="0.4" />
43+
<GradientStop Color="Red"
44+
Offset="0.5" />
45+
<GradientStop Color="Yellow"
46+
Offset="0.6" />
47+
<GradientStop Color="Red"
48+
Offset="0.7" />
49+
<GradientStop Color="Blue"
50+
Offset="0.8" />
51+
<GradientStop Color="LimeGreen"
52+
Offset="0.9" />
53+
<GradientStop Color="Blue"
54+
Offset="1.0" />
55+
</LinearGradientBrush>
56+
</Border.Background>
57+
</Border>
58+
</Grid>
59+
</StackPanel>
4860
</UserControl>

src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.wasm.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public static void SetBorder(UIElement element, Thickness thickness, Brush brush
9090
("border-style", "solid"),
9191
("border-color", ""),
9292
("border-image", border),
93-
("border-width", borderWidth));
93+
("border-width", borderWidth),
94+
("border-image-slice", "1"));
9495
break;
9596
case AcrylicBrush acrylicBrush:
9697
var acrylicFallbackColor = acrylicBrush.FallbackColorWithOpacity;

0 commit comments

Comments
 (0)