优化更新代码,添加界面功能并整合
This commit is contained in:
BIN
WPFluent/Controls/Badge/Badge.bmp
Normal file
BIN
WPFluent/Controls/Badge/Badge.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 824 B |
33
WPFluent/Controls/Badge/Badge.cs
Normal file
33
WPFluent/Controls/Badge/Badge.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
|
||||
// https://docs.microsoft.com/en-us/fluent-ui/web-components/components/badge
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WPFluent.Controls;
|
||||
|
||||
/// <summary>
|
||||
/// Used to highlight an item, attract attention or flag status.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code lang="xml"> /// <ui:Badge Appearance="Secondary"> /// <TextBox Text="Hello" /> ///
|
||||
/// </ui:Badge> ///</code>
|
||||
/// </example>
|
||||
public class Badge : System.Windows.Controls.ContentControl, IAppearanceControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifies the <see cref="Appearance"/> dependency property.
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty AppearanceProperty = DependencyProperty.Register(
|
||||
nameof(Appearance),
|
||||
typeof(Controls.ControlAppearance),
|
||||
typeof(Badge),
|
||||
new PropertyMetadata(Controls.ControlAppearance.Primary));
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Controls.ControlAppearance Appearance
|
||||
{
|
||||
get => (Controls.ControlAppearance)GetValue(AppearanceProperty);
|
||||
set => SetValue(AppearanceProperty, value);
|
||||
}
|
||||
}
|
||||
75
WPFluent/Controls/Badge/Badge.xaml
Normal file
75
WPFluent/Controls/Badge/Badge.xaml
Normal file
@@ -0,0 +1,75 @@
|
||||
<!--
|
||||
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"
|
||||
xmlns:controls="clr-namespace:WPFluent.Controls">
|
||||
|
||||
<Style TargetType="{x:Type controls:Badge}">
|
||||
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}" />
|
||||
<Setter Property="Background" Value="{DynamicResource BadgeBackground}" />
|
||||
<!--<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentBrush}" />-->
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Padding" Value="4" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type controls:Badge}">
|
||||
<Border
|
||||
x:Name="Border"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="Appearance" Value="Primary">
|
||||
<Setter Property="Foreground" Value="{DynamicResource BadgeForeground}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Transparent">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
|
||||
<Setter TargetName="Border" Property="Background" Value="Transparent" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Secondary">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Info">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource PaletteLightBlueBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Caution">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource PaletteOrangeBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Danger">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource PaletteRedBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Success">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource PaletteGreenBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Dark">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlStrongFillColorDarkBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorLightPrimaryBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="Appearance" Value="Light">
|
||||
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlStrongFillColorLightBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDarkPrimaryBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user