优化更新代码,添加界面功能并整合
This commit is contained in:
19
WPFluent/Controls/TextBlock/FontTypography.cs
Normal file
19
WPFluent/Controls/TextBlock/FontTypography.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Defines several predefined text styles that you can apply to some elements responsible for displaying it. <para><see
|
||||
/// href="https://learn.microsoft.com/en-us/windows/apps/design/style/typography"/></para>
|
||||
/// </summary>
|
||||
public enum FontTypography
|
||||
{
|
||||
Caption,
|
||||
Body,
|
||||
BodyStrong,
|
||||
Subtitle,
|
||||
Title,
|
||||
TitleLarge,
|
||||
Display,
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
25
WPFluent/Controls/TextBlock/TextBlock.xaml
Normal file
25
WPFluent/Controls/TextBlock/TextBlock.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
This Source Code Form is subject to the terms of the MIT License.
|
||||
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
|
||||
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
|
||||
All Rights Reserved.
|
||||
-->
|
||||
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<Style TargetType="{x:Type TextBlock}">
|
||||
|
||||
<!--<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>-->
|
||||
|
||||
<!-- The Display option causes a large aliasing effect -->
|
||||
<!--<Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />-->
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
30
WPFluent/Controls/TextBlock/TextColor.cs
Normal file
30
WPFluent/Controls/TextBlock/TextColor.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Colors for UI labels and static text
|
||||
/// </summary>
|
||||
public enum TextColor
|
||||
{
|
||||
/// <summary>
|
||||
/// Rest or Hover
|
||||
/// </summary>
|
||||
Primary,
|
||||
|
||||
/// <summary>
|
||||
/// Rest or Hover
|
||||
/// </summary>
|
||||
Secondary,
|
||||
|
||||
/// <summary>
|
||||
/// Pressed only (not accessible)
|
||||
/// </summary>
|
||||
Tertiary,
|
||||
|
||||
/// <summary>
|
||||
/// Disabled only (not accessible)
|
||||
/// </summary>
|
||||
Disabled,
|
||||
}
|
||||
Reference in New Issue
Block a user