Files
Shrlalgo.RvKits/Melskin/Controls/Chip.xaml.cs

98 lines
2.6 KiB
C#
Raw Normal View History

2025-08-12 23:08:54 +08:00
using System.Windows.Input;
2026-01-02 17:30:41 +08:00
namespace Melskin.Controls;
2025-08-12 23:08:54 +08:00
/// <summary>
2025-12-28 11:47:54 +08:00
/// 标签、纸片、徽章可点击跳转链接
2025-08-12 23:08:54 +08:00
/// </summary>
2025-10-10 11:19:58 +08:00
public class Chip : ContentControl
2025-08-12 23:08:54 +08:00
{
2025-10-10 11:19:58 +08:00
static Chip()
2025-08-12 23:08:54 +08:00
{
2025-10-10 11:19:58 +08:00
DefaultStyleKeyProperty.OverrideMetadata(typeof(Chip), new FrameworkPropertyMetadata(typeof(Chip)));
2025-08-12 23:08:54 +08:00
}
/// <inheritdoc/>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.MouseLeftButtonDown += Tag_MouseLeftButtonDown;
}
#region
/// <summary>
/// 标题
/// </summary>
public static readonly DependencyProperty HeaderProperty =
2025-10-10 11:19:58 +08:00
DependencyProperty.Register(nameof(Header), typeof(object), typeof(Chip), new PropertyMetadata(default(object)));
2025-08-12 23:08:54 +08:00
/// <summary>
/// 标题
/// </summary>
public object Header
{
get => (object)GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}
/// <summary>
/// 标题背景色
/// </summary>
public static readonly DependencyProperty HeadBackgroundProperty =
2025-10-10 11:19:58 +08:00
DependencyProperty.Register(nameof(HeadBackground), typeof(Brush), typeof(Chip), new PropertyMetadata(default(Brush)));
2025-08-12 23:08:54 +08:00
/// <summary>
/// 标题背景色
/// </summary>
public Brush HeadBackground
{
get => (Brush)GetValue(HeadBackgroundProperty);
set => SetValue(HeadBackgroundProperty, value);
}
/// <summary>
/// 标题前景色
/// </summary>
public static readonly DependencyProperty HeadForegroundProperty =
2025-10-10 11:19:58 +08:00
DependencyProperty.Register(nameof(HeadForeground), typeof(Brush), typeof(Chip), new PropertyMetadata(default(Brush)));
2025-08-12 23:08:54 +08:00
/// <summary>
/// 标题前景色
/// </summary>
public Brush HeadForeground
{
get => (Brush)GetValue(HeadForegroundProperty);
set => SetValue(HeadForegroundProperty, value);
}
/// <summary>
/// 链接
/// </summary>
public static readonly DependencyProperty UrlProperty =
2025-10-10 11:19:58 +08:00
DependencyProperty.Register(nameof(Url), typeof(string), typeof(Chip), new PropertyMetadata(default(string)));
2025-08-12 23:08:54 +08:00
/// <summary>
/// 链接
/// </summary>
public string Url
{
get => (string)GetValue(UrlProperty);
set => SetValue(UrlProperty, value);
}
#endregion
#region
private void Tag_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!string.IsNullOrEmpty(Url))
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Url) { UseShellExecute = true });
}
}
#endregion
}