优化更新代码,添加界面功能并整合
This commit is contained in:
70
WPFluent/Controls/TextBlock/TextBlock.cs
Normal file
70
WPFluent/Controls/TextBlock/TextBlock.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using WPFluent.Extensions;
|
||||
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Extended <see cref="System.Windows.Controls.TextBlock"/> with additional parameters like <see
|
||||
/// cref="FontTypography"/>.
|
||||
/// </summary>
|
||||
public class TextBlock : System.Windows.Controls.TextBlock
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="FontTypography"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty FontTypographyProperty = DependencyProperty.Register(
|
||||
nameof(FontTypography),
|
||||
typeof(FontTypography),
|
||||
typeof(TextBlock),
|
||||
new PropertyMetadata(
|
||||
FontTypography.Body,
|
||||
static(o, args) =>
|
||||
{
|
||||
((TextBlock)o).OnFontTypographyChanged((FontTypography)args.NewValue);
|
||||
}));
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="Appearance"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty AppearanceProperty = DependencyProperty.Register(
|
||||
nameof(Appearance),
|
||||
typeof(TextColor),
|
||||
typeof(TextBlock),
|
||||
new PropertyMetadata(
|
||||
TextColor.Primary,
|
||||
static(o, args) =>
|
||||
{
|
||||
((TextBlock)o).OnAppearanceChanged((TextColor)args.NewValue);
|
||||
}));
|
||||
|
||||
public TextBlock()
|
||||
{
|
||||
var defaultFontTypography = (FontTypography)FontTypographyProperty.DefaultMetadata.DefaultValue;
|
||||
SetResourceReference(StyleProperty, defaultFontTypography.ToResourceValue());
|
||||
}
|
||||
|
||||
private void OnAppearanceChanged(TextColor textColor)
|
||||
{ SetResourceReference(ForegroundProperty, textColor.ToResourceValue()); }
|
||||
|
||||
private void OnFontTypographyChanged(FontTypography newTypography)
|
||||
{ SetResourceReference(StyleProperty, newTypography.ToResourceValue()); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color of the text.
|
||||
/// </summary>
|
||||
public TextColor Appearance
|
||||
{
|
||||
get => (TextColor)GetValue(AppearanceProperty);
|
||||
set => SetValue(AppearanceProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="FontTypography"/> of the text.
|
||||
/// </summary>
|
||||
public FontTypography FontTypography
|
||||
{
|
||||
get => (FontTypography)GetValue(FontTypographyProperty);
|
||||
set => SetValue(FontTypographyProperty, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user