Skip to content

Commit

Permalink
Simplify ContentPresenterEx implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Dec 4, 2020
1 parent 8fbc66b commit 92ecdb9
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions ModernWpf/Controls/ContentPresenterEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,7 @@ public Brush Foreground
/// DependencyProperty for <see cref="LineHeight" /> property.
/// </summary>
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));

/// <summary>
/// The LineHeight property specifies the height of each generated line box.
Expand All @@ -144,10 +128,7 @@ public double LineHeight
/// DependencyProperty for <see cref="LineStackingStrategy" /> property.
/// </summary>
public static readonly DependencyProperty LineStackingStrategyProperty =
Block.LineStackingStrategyProperty.AddOwner(
typeof(ContentPresenterEx),
new FrameworkPropertyMetadata(
new PropertyChangedCallback(OnLineStackingStrategyChanged)));
Block.LineStackingStrategyProperty.AddOwner(typeof(ContentPresenterEx));

/// <summary>
/// The LineStackingStrategy property specifies how lines are placed
Expand All @@ -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;
}
}

/// <summary>
/// DependencyProperty for <see cref="TextWrapping" /> property.
/// </summary>
Expand Down Expand Up @@ -218,17 +186,13 @@ private TextBlock TextBlock
{
if (_textBlock != null)
{
_textBlock.ClearValue(TextBlock.LineHeightProperty);
_textBlock.ClearValue(TextBlock.LineStackingStrategyProperty);
_textBlock.ClearValue(TextBlock.TextWrappingProperty);
}

_textBlock = value;

if (_textBlock != null)
{
_textBlock.LineHeight = LineHeight;
_textBlock.LineStackingStrategy = LineStackingStrategy;
_textBlock.TextWrapping = TextWrapping;
}
}
Expand All @@ -242,17 +206,13 @@ private AccessText AccessText
{
if (_accessText != null)
{
_accessText.ClearValue(AccessText.LineHeightProperty);
_accessText.ClearValue(AccessText.LineStackingStrategyProperty);
_accessText.ClearValue(AccessText.TextWrappingProperty);
}

_accessText = value;

if (_accessText != null)
{
_accessText.LineHeight = LineHeight;
_accessText.LineStackingStrategy = LineStackingStrategy;
_accessText.TextWrapping = TextWrapping;
}
}
Expand Down

0 comments on commit 92ecdb9

Please sign in to comment.