private static void HandleIsEnabledChanged( DependencyObject source, DependencyPropertyChangedEventArgs e) { if (!(source is TextBlock textBlock)) { return; } if ((bool)e.OldValue) { FadeTrimming.Fader fader = FadeTrimming.GetFader((DependencyObject)textBlock); if (fader != null) { fader.Detach(); FadeTrimming.SetFader((DependencyObject)textBlock, (FadeTrimming.Fader)null); } textBlock.Loaded -= new RoutedEventHandler(FadeTrimming.HandleTextBlockLoaded); textBlock.Unloaded -= new RoutedEventHandler(FadeTrimming.HandleTextBlockUnloaded); } if (!(bool)e.NewValue) { return; } textBlock.Loaded += new RoutedEventHandler(FadeTrimming.HandleTextBlockLoaded); textBlock.Unloaded += new RoutedEventHandler(FadeTrimming.HandleTextBlockUnloaded); FadeTrimming.Fader fader1 = new FadeTrimming.Fader(textBlock); FadeTrimming.SetFader((DependencyObject)textBlock, fader1); fader1.Attach(); }
private static void HandleTextBlockLoaded(object sender, RoutedEventArgs e) { if (!(sender is DependencyObject dependencyObject)) { return; } FadeTrimming.GetFader(dependencyObject)?.Attach(); }
private static void HandleVerticalFadingEnabled( DependencyObject source, DependencyPropertyChangedEventArgs e) { if (!(source is TextBlock textBlock)) { return; } FadeTrimming.GetFader((DependencyObject)textBlock)?.ToggleVerticalFading((bool)e.NewValue); }
private void UpdateForegroundBrush(object sender, EventArgs e) { Geometry layoutClip = LayoutInformation.GetLayoutClip((FrameworkElement)this._textBlock); Rect bounds; int num; if (layoutClip != null) { if (this._textBlock.TextWrapping == TextWrapping.NoWrap) { bounds = layoutClip.Bounds; if (bounds.Width > 0.0) { bounds = layoutClip.Bounds; if (bounds.Width < this._textBlock.ActualWidth) { num = 1; goto label_10; } } } if (this._verticalFadingEnabled && this._textBlock.TextWrapping == TextWrapping.Wrap) { bounds = layoutClip.Bounds; if (bounds.Height > 0.0) { bounds = layoutClip.Bounds; num = bounds.Height < this._textBlock.ActualHeight ? 1 : 0; goto label_10; } } num = 0; } else { num = 0; } label_10: bool flag1 = num != 0; if (this._isClipped && !flag1) { this._textBlock.OpacityMask = this._opacityMask; this._brush = (LinearGradientBrush)null; this._isClipped = false; } if (!flag1) { return; } bounds = layoutClip.Bounds; double width = bounds.Width; bounds = layoutClip.Bounds; double height = bounds.Height; bool flag2 = this._textBlock.TextWrapping == TextWrapping.Wrap; if (this._brush == null) { this._brush = flag2 ? this.GetVerticalClipBrush(height) : this.GetHorizontalClipBrush(width); this._textBlock.OpacityMask = (Brush)this._brush; } else if (flag2 && FadeTrimming.VerticalBrushNeedsUpdating(this._brush, height)) { this._brush.EndPoint = new Point(0.0, height); this._brush.GradientStops[1].Offset = (height - 20.0) / height; } else if (!flag2 && FadeTrimming.HorizontalBrushNeedsUpdating(this._brush, width)) { this._brush.EndPoint = new Point(width, 0.0); this._brush.GradientStops[1].Offset = (width - 10.0) / width; } this._isClipped = true; }