diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media/GradientBrushTests/GradientsPage.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media/GradientBrushTests/GradientsPage.xaml index 1c9ea41ba481..a0faa2b47422 100644 --- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media/GradientBrushTests/GradientsPage.xaml +++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media/GradientBrushTests/GradientsPage.xaml @@ -10,7 +10,7 @@ Radial Gradient as background on a Rectangle + Border - + @@ -22,7 +22,7 @@ - + @@ -37,7 +37,7 @@ Radial Gradient as border/stroke on a Rectangle + Border - + @@ -49,7 +49,7 @@ - + @@ -64,7 +64,7 @@ Linear Gradient as background on a Rectangle + Border (relative + absolute) - + @@ -76,7 +76,7 @@ - + @@ -88,9 +88,9 @@ - + - + @@ -100,9 +100,9 @@ - + - + @@ -115,7 +115,7 @@ Linear Gradient as border/stroke on a Rectangle + Border (relative + absolute) - + @@ -127,7 +127,7 @@ - + @@ -139,9 +139,9 @@ - + - + @@ -151,9 +151,9 @@ - + - + @@ -164,5 +164,32 @@ + Text with Radial/Linear gradient as foreground brush + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Uno.UI.Wasm/WasmCSS/Uno.UI.css b/src/Uno.UI.Wasm/WasmCSS/Uno.UI.css index e1239c72cc19..0e7cc576e2b6 100644 --- a/src/Uno.UI.Wasm/WasmCSS/Uno.UI.css +++ b/src/Uno.UI.Wasm/WasmCSS/Uno.UI.css @@ -99,6 +99,10 @@ embed.uno-frameworkelement.uno-unarranged { -moz-user-select: none; /* Firefox */ -ms-user-select: none; /* Internet Explorer/Edge */ user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */ + + -ms-background-clip: text !important; + -webkit-background-clip: text !important; + background-clip: text !important; } .uno-buttonbase { diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs b/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs index 2f080c11ff8d..4f37ea26b349 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs @@ -367,10 +367,12 @@ Brush Foreground get { return (Brush)this.GetValue(ForegroundProperty); } set { +#if !__WASM__ if (!(Foreground is SolidColorBrush)) { throw new NotSupportedException(); } +#endif this.SetValue(ForegroundProperty, value); } diff --git a/src/Uno.UI/UI/Xaml/Documents/UIElementTextHelper.wasm.cs b/src/Uno.UI/UI/Xaml/Documents/UIElementTextHelper.wasm.cs index b74e72d66ef2..6f05f5781358 100644 --- a/src/Uno.UI/UI/Xaml/Documents/UIElementTextHelper.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Documents/UIElementTextHelper.wasm.cs @@ -1,5 +1,6 @@ using System; using System.Web; +using Windows.Foundation; using Windows.UI.Text; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -139,12 +140,20 @@ internal static void SetForeground(this UIElement element, object localValue) case SolidColorBrush scb: element.SetStyle("color", scb.ColorWithOpacity.ToHexString()); break; + case GradientBrush gradient: + element.SetStyle( + ("background", gradient.ToCssString(element.RenderSize)), + ("color", "transparent"), + ("background-clip", "text") + ); + break; case UnsetValue uv: + // TODO: support other foreground types default: - element.ResetStyle("color"); + element.ResetStyle("color", "background", "background-clip"); break; } } diff --git a/src/Uno.UI/UI/Xaml/Media/LinearGradientBrush.cs b/src/Uno.UI/UI/Xaml/Media/LinearGradientBrush.cs index fc779854c46e..35753ede0366 100644 --- a/src/Uno.UI/UI/Xaml/Media/LinearGradientBrush.cs +++ b/src/Uno.UI/UI/Xaml/Media/LinearGradientBrush.cs @@ -39,6 +39,5 @@ public Point EndPoint typeof(LinearGradientBrush), new PropertyMetadata(new Point(1,1)) ); - } }