From 92ecdb90ee1d56197abde4a593c1050bd78060d7 Mon Sep 17 00:00:00 2001 From: Yimeng Wu Date: Sat, 5 Dec 2020 01:36:05 +0800 Subject: [PATCH] Simplify ContentPresenterEx implementation --- ModernWpf/Controls/ContentPresenterEx.cs | 44 ++---------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/ModernWpf/Controls/ContentPresenterEx.cs b/ModernWpf/Controls/ContentPresenterEx.cs index d9aadc42..6cd9c80d 100644 --- a/ModernWpf/Controls/ContentPresenterEx.cs +++ b/ModernWpf/Controls/ContentPresenterEx.cs @@ -112,23 +112,7 @@ public Brush Foreground /// DependencyProperty for property. /// public static readonly DependencyProperty LineHeightProperty = - Block.LineHeightProperty.AddOwner( - typeof(ContentPresenterEx), - new FrameworkPropertyMetadata( - new PropertyChangedCallback(OnLineHeightChanged))); - - private static void OnLineHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ctrl = (ContentPresenterEx)d; - if (ctrl.TextBlock != null) - { - ctrl.TextBlock.LineHeight = (double)e.NewValue; - } - else if (ctrl.AccessText != null) - { - ctrl.AccessText.LineHeight = (double)e.NewValue; - } - } + Block.LineHeightProperty.AddOwner(typeof(ContentPresenterEx)); /// /// The LineHeight property specifies the height of each generated line box. @@ -144,10 +128,7 @@ public double LineHeight /// DependencyProperty for property. /// public static readonly DependencyProperty LineStackingStrategyProperty = - Block.LineStackingStrategyProperty.AddOwner( - typeof(ContentPresenterEx), - new FrameworkPropertyMetadata( - new PropertyChangedCallback(OnLineStackingStrategyChanged))); + Block.LineStackingStrategyProperty.AddOwner(typeof(ContentPresenterEx)); /// /// The LineStackingStrategy property specifies how lines are placed @@ -158,19 +139,6 @@ public LineStackingStrategy LineStackingStrategy set { SetValue(LineStackingStrategyProperty, value); } } - private static void OnLineStackingStrategyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ctrl = (ContentPresenterEx)d; - if (ctrl.TextBlock != null) - { - ctrl.TextBlock.LineStackingStrategy = (LineStackingStrategy)e.NewValue; - } - else if (ctrl.AccessText != null) - { - ctrl.AccessText.LineStackingStrategy = (LineStackingStrategy)e.NewValue; - } - } - /// /// DependencyProperty for property. /// @@ -218,8 +186,6 @@ private TextBlock TextBlock { if (_textBlock != null) { - _textBlock.ClearValue(TextBlock.LineHeightProperty); - _textBlock.ClearValue(TextBlock.LineStackingStrategyProperty); _textBlock.ClearValue(TextBlock.TextWrappingProperty); } @@ -227,8 +193,6 @@ private TextBlock TextBlock if (_textBlock != null) { - _textBlock.LineHeight = LineHeight; - _textBlock.LineStackingStrategy = LineStackingStrategy; _textBlock.TextWrapping = TextWrapping; } } @@ -242,8 +206,6 @@ private AccessText AccessText { if (_accessText != null) { - _accessText.ClearValue(AccessText.LineHeightProperty); - _accessText.ClearValue(AccessText.LineStackingStrategyProperty); _accessText.ClearValue(AccessText.TextWrappingProperty); } @@ -251,8 +213,6 @@ private AccessText AccessText if (_accessText != null) { - _accessText.LineHeight = LineHeight; - _accessText.LineStackingStrategy = LineStackingStrategy; _accessText.TextWrapping = TextWrapping; } }