internal static void SetForeground(this UIElement element, object localValue) { switch (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 AcrylicBrush acrylic: acrylic.Apply(element); element.SetStyle("background-clip", "text"); break; case UnsetValue uv: // TODO: support other foreground types default: element.ResetStyle("color", "background", "background-clip"); AcrylicBrush.ResetStyle(element); break; } }
internal static void SetForeground(this UIElement element, object localValue) { var brushSubscription = _imageBrushSubscription.GetValue(element, "foreground", () => new SerialDisposable()); brushSubscription.Disposable = null; switch (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 ImageBrush imageBrush: brushSubscription.Disposable = imageBrush.Subscribe(img => { switch (img.Kind) { case ImageDataKind.Empty: case ImageDataKind.Error: element.ResetStyle( "background-color", "background-image", "background-size"); element.SetStyle( ("color", "transparent"), ("background-clip", "text")); break; case ImageDataKind.DataUri: case ImageDataKind.Url: default: element.SetStyle( ("color", "transparent"), ("background-clip", "text"), ("background-color", ""), ("background-origin", "content-box"), ("background-position", imageBrush.ToCssPosition()), ("background-size", imageBrush.ToCssBackgroundSize()), ("background-image", "url(" + img.Value + ")") ); break; } }); break; case AcrylicBrush acrylic: acrylic.Apply(element); element.SetStyle("background-clip", "text"); break; case UnsetValue uv: // TODO: support other foreground types default: element.ResetStyle("color", "background", "background-clip"); AcrylicBrush.ResetStyle(element); break; } }
internal void SetForeground(object localValue) { if (_brushSubscription != null) { _brushSubscription.Disposable = null; } switch (localValue) { case SolidColorBrush scb: WindowManagerInterop.SetElementColor(HtmlId, scb.ColorWithOpacity); break; case GradientBrush gradient: this.SetStyle( ("background", gradient.ToCssString(this.RenderSize)), ("color", "transparent"), ("background-clip", "text") ); break; case ImageBrush imageBrush: _brushSubscription ??= new SerialDisposable(); _brushSubscription.Disposable = imageBrush.Subscribe(img => { switch (img.Kind) { case ImageDataKind.Empty: case ImageDataKind.Error: this.ResetStyle( "background-color", "background-image", "background-size"); this.SetStyle( ("color", "transparent"), ("background-clip", "text")); break; case ImageDataKind.DataUri: case ImageDataKind.Url: default: this.SetStyle( ("color", "transparent"), ("background-clip", "text"), ("background-color", ""), ("background-origin", "content-box"), ("background-position", imageBrush.ToCssPosition()), ("background-size", imageBrush.ToCssBackgroundSize()), ("background-image", "url(" + img.Value + ")") ); break; } }); break; case AcrylicBrush acrylic: acrylic.Apply(this); this.SetStyle("background-clip", "text"); break; case UnsetValue uv: // TODO: support other foreground types default: this.ResetStyle("color", "background", "background-clip"); AcrylicBrush.ResetStyle(this); break; } }