优化更新代码,添加界面功能并整合
This commit is contained in:
74
WPFluent/Controls/InfoBadge/InfoBadge.cs
Normal file
74
WPFluent/Controls/InfoBadge/InfoBadge.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
|
||||
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
public class InfoBadge : System.Windows.Controls.Control
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="CornerRadius"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register(
|
||||
nameof(CornerRadius),
|
||||
typeof(CornerRadius),
|
||||
typeof(InfoBadge),
|
||||
new FrameworkPropertyMetadata(
|
||||
new CornerRadius(8),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="Icon"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
|
||||
nameof(Icon),
|
||||
typeof(IconElement),
|
||||
typeof(InfoBadge),
|
||||
new PropertyMetadata(null, null, IconElement.Coerce));
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="Severity"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty SeverityProperty = DependencyProperty.Register(
|
||||
nameof(Severity),
|
||||
typeof(InfoBadgeSeverity),
|
||||
typeof(InfoBadge),
|
||||
new PropertyMetadata(InfoBadgeSeverity.Informational));
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="Value"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
|
||||
nameof(Value),
|
||||
typeof(string),
|
||||
typeof(InfoBadge),
|
||||
new PropertyMetadata(string.Empty));
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the <see cref="CornerRadius"/>.
|
||||
/// </summary>
|
||||
public CornerRadius CornerRadius
|
||||
{
|
||||
get => (CornerRadius)GetValue(CornerRadiusProperty);
|
||||
set => SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets displayed <see cref="IconElement"/>.
|
||||
/// </summary>
|
||||
[Bindable(true)]
|
||||
[Category("Appearance")]
|
||||
public IconElement? Icon { get => (IconElement?)GetValue(IconProperty); set => SetValue(IconProperty, value); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the <see cref="Severity"/>.
|
||||
/// </summary>
|
||||
public InfoBadgeSeverity Severity
|
||||
{
|
||||
get => (InfoBadgeSeverity)GetValue(SeverityProperty);
|
||||
set => SetValue(SeverityProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the <see cref="Value"/>.
|
||||
/// </summary>
|
||||
public string Value { get => (string)GetValue(ValueProperty); set => SetValue(ValueProperty, value); }
|
||||
}
|
||||
191
WPFluent/Controls/InfoBadge/InfoBadge.xaml
Normal file
191
WPFluent/Controls/InfoBadge/InfoBadge.xaml
Normal file
@@ -0,0 +1,191 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:WPFluent.Controls">
|
||||
|
||||
<CornerRadius x:Key="ValueInfoBadgeStyleCornerRadius">8</CornerRadius>
|
||||
<Thickness x:Key="IconBadgeMargin">2</Thickness>
|
||||
|
||||
<Style x:Key="DotInfoBadgeStyle" TargetType="{x:Type controls:InfoBadge}">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="{DynamicResource InfoBadgeInformationSeverityBackgroundBrush}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:InfoBadge}">
|
||||
<Grid x:Name="InfoBadgeRoot">
|
||||
<Border
|
||||
x:Name="ContentBorder"
|
||||
Width="6"
|
||||
Height="6"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
Opacity="{TemplateBinding Opacity}" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="Severity" Value="Attention">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeAttentionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Informational">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeInformationalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Success">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeSuccessSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Caution">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCautionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Critical">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCriticalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
</Style>
|
||||
|
||||
<Style x:Key="IconInfoBadgeStyle" TargetType="{x:Type controls:InfoBadge}">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="{DynamicResource InfoBadgeInformationSeverityBackgroundBrush}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:InfoBadge}">
|
||||
<Grid x:Name="InfoBadgeRoot">
|
||||
<Border
|
||||
x:Name="ContentBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
Opacity="{TemplateBinding Opacity}">
|
||||
<ContentPresenter
|
||||
x:Name="ControlIcon"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Content="{TemplateBinding Icon}"
|
||||
Focusable="False"
|
||||
TextElement.FontSize="{TemplateBinding FontSize}"
|
||||
TextElement.Foreground="{DynamicResource InfoBadgeValueForeground}" />
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="Severity" Value="Attention">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeAttentionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Informational">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeInformationalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Success">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeSuccessSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Caution">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCautionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Critical">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCriticalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
|
||||
</ControlTemplate.Triggers>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
</Style>
|
||||
|
||||
<Style x:Key="ValueInfoBadgeStyle" TargetType="{x:Type controls:InfoBadge}">
|
||||
<Setter Property="Background">
|
||||
<Setter.Value>
|
||||
<SolidColorBrush Color="{DynamicResource InfoBadgeInformationSeverityBackgroundBrush}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="FontWeight" Value="Normal" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:InfoBadge}">
|
||||
<Grid x:Name="InfoBadgeRoot">
|
||||
<Border
|
||||
x:Name="ContentBorder"
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}"
|
||||
MinWidth="16"
|
||||
MinHeight="16"
|
||||
Margin="{StaticResource IconBadgeMargin}"
|
||||
Padding="3,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
CornerRadius="{StaticResource ValueInfoBadgeStyleCornerRadius}"
|
||||
Opacity="{TemplateBinding Opacity}">
|
||||
<TextBlock
|
||||
x:Name="TextBlock"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Focusable="False"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
Foreground="{DynamicResource InfoBadgeValueForeground}"
|
||||
Text="{TemplateBinding Value}"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="Severity" Value="Attention">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeAttentionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Informational">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeInformationalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Success">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeSuccessSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Caution">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCautionSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Severity" Value="Critical">
|
||||
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource InfoBadgeCriticalSeverityBackgroundBrush}" />
|
||||
</Trigger>
|
||||
|
||||
|
||||
</ControlTemplate.Triggers>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style BasedOn="{StaticResource ValueInfoBadgeStyle}" TargetType="{x:Type controls:InfoBadge}" />
|
||||
|
||||
</ResourceDictionary>
|
||||
33
WPFluent/Controls/InfoBadge/InfoBadgeSeverity.cs
Normal file
33
WPFluent/Controls/InfoBadge/InfoBadgeSeverity.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
public enum InfoBadgeSeverity
|
||||
{
|
||||
/// <summary>
|
||||
/// Communicates that the InfoBadge is displaying general information that requires the user's attention.
|
||||
/// </summary>
|
||||
Attention = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Communicates that the InfoBadge is displaying general information that requires the user's attention.
|
||||
/// </summary>
|
||||
Informational = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Communicates that the InfoBadge is displaying general information that requires the user's attention.
|
||||
/// </summary>
|
||||
Success = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Communicates that the InfoBadge is displaying general information that requires the user's attention.
|
||||
/// </summary>
|
||||
Caution = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Communicates that the InfoBadge is displaying general information that requires the user's attention.
|
||||
/// </summary>
|
||||
Critical = 4,
|
||||
}
|
||||
Reference in New Issue
Block a user