-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTextBlockService.cs
More file actions
83 lines (76 loc) · 3.42 KB
/
TextBlockService.cs
File metadata and controls
83 lines (76 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using BytecodeApi.Wpf.Extensions;
using System.Windows;
using System.Windows.Controls;
namespace BytecodeApi.Wpf.Services;
/// <summary>
/// Helper class for the WPF <see cref="TextBlock" /> control.
/// </summary>
public static class TextBlockService
{
/// <summary>
/// Identifies the <see cref="TextBlockService" />.TextWrapping dependency property. This field is read-only.
/// </summary>
public static readonly DependencyProperty TextWrappingProperty = DependencyProperty.RegisterAttached<ContentControl, TextWrapping>("TextWrapping", new FrameworkPropertyMetadata(TextWrapping.NoWrap, FrameworkPropertyMetadataOptions.Inherits, TextWrapping_Changed));
/// <summary>
/// Identifies the <see cref="TextBlockService" />.TextTrimming dependency property. This field is read-only.
/// </summary>
public static readonly DependencyProperty TextTrimmingProperty = DependencyProperty.RegisterAttached<ContentControl, TextTrimming>("TextTrimming", new FrameworkPropertyMetadata(TextTrimming.None, FrameworkPropertyMetadataOptions.Inherits, TextTrimming_Changed));
/// <summary>
/// Returns the <see cref="TextBlock.TextWrapping" /> property.
/// </summary>
/// <param name="dependencyObject">The <see cref="TextBlock" /> to check.</param>
/// <returns>
/// The <see cref="TextBlock.TextWrapping" /> property.
/// </returns>
public static TextWrapping GetTextWrapping(DependencyObject dependencyObject)
{
Check.ArgumentNull(dependencyObject);
return dependencyObject.GetValue<TextWrapping>(TextWrappingProperty);
}
/// <summary>
/// Sets the <see cref="TextBlock.TextWrapping" /> property.
/// </summary>
/// <param name="dependencyObject">The <see cref="TextBlock" /> to modify.</param>
/// <param name="value">A <see cref="TextWrapping" /> value for the <see cref="TextBlock" />.</param>
public static void SetTextWrapping(DependencyObject dependencyObject, TextWrapping value)
{
Check.ArgumentNull(dependencyObject);
dependencyObject.SetValue(TextWrappingProperty, value);
}
/// <summary>
/// Returns the <see cref="TextBlock.TextTrimming" /> property.
/// </summary>
/// <param name="dependencyObject">The <see cref="TextBlock" /> to check.</param>
/// <returns>
/// The <see cref="TextBlock.TextTrimming" /> property.
/// </returns>
public static TextTrimming GetTextTrimming(DependencyObject dependencyObject)
{
Check.ArgumentNull(dependencyObject);
return dependencyObject.GetValue<TextTrimming>(TextTrimmingProperty);
}
/// <summary>
/// Sets the <see cref="TextBlock.TextTrimming" /> property.
/// </summary>
/// <param name="dependencyObject">The <see cref="TextBlock" /> to modify.</param>
/// <param name="value">A <see cref="TextTrimming" /> value for the <see cref="TextBlock" />.</param>
public static void SetTextTrimming(DependencyObject dependencyObject, TextTrimming value)
{
Check.ArgumentNull(dependencyObject);
dependencyObject.SetValue(TextTrimmingProperty, value);
}
private static void TextWrapping_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is TextBlock textBlock)
{
textBlock.TextWrapping = (TextWrapping)e.NewValue;
}
}
private static void TextTrimming_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is TextBlock textBlock)
{
textBlock.TextTrimming = (TextTrimming)e.NewValue;
}
}
}