98 lines
2.6 KiB
C#
98 lines
2.6 KiB
C#
using System.Windows.Input;
|
|
|
|
namespace Melskin.Controls;
|
|
|
|
/// <summary>
|
|
/// 标签、纸片、徽章可点击跳转链接
|
|
/// </summary>
|
|
public class Chip : ContentControl
|
|
{
|
|
static Chip()
|
|
{
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(Chip), new FrameworkPropertyMetadata(typeof(Chip)));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public override void OnApplyTemplate()
|
|
{
|
|
base.OnApplyTemplate();
|
|
|
|
this.MouseLeftButtonDown += Tag_MouseLeftButtonDown;
|
|
}
|
|
|
|
#region 属性
|
|
|
|
/// <summary>
|
|
/// 标题
|
|
/// </summary>
|
|
public static readonly DependencyProperty HeaderProperty =
|
|
DependencyProperty.Register(nameof(Header), typeof(object), typeof(Chip), new PropertyMetadata(default(object)));
|
|
|
|
/// <summary>
|
|
/// 标题
|
|
/// </summary>
|
|
public object Header
|
|
{
|
|
get => (object)GetValue(HeaderProperty);
|
|
set => SetValue(HeaderProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标题背景色
|
|
/// </summary>
|
|
public static readonly DependencyProperty HeadBackgroundProperty =
|
|
DependencyProperty.Register(nameof(HeadBackground), typeof(Brush), typeof(Chip), new PropertyMetadata(default(Brush)));
|
|
|
|
/// <summary>
|
|
/// 标题背景色
|
|
/// </summary>
|
|
public Brush HeadBackground
|
|
{
|
|
get => (Brush)GetValue(HeadBackgroundProperty);
|
|
set => SetValue(HeadBackgroundProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 标题前景色
|
|
/// </summary>
|
|
public static readonly DependencyProperty HeadForegroundProperty =
|
|
DependencyProperty.Register(nameof(HeadForeground), typeof(Brush), typeof(Chip), new PropertyMetadata(default(Brush)));
|
|
|
|
/// <summary>
|
|
/// 标题前景色
|
|
/// </summary>
|
|
public Brush HeadForeground
|
|
{
|
|
get => (Brush)GetValue(HeadForegroundProperty);
|
|
set => SetValue(HeadForegroundProperty, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 链接
|
|
/// </summary>
|
|
public static readonly DependencyProperty UrlProperty =
|
|
DependencyProperty.Register(nameof(Url), typeof(string), typeof(Chip), new PropertyMetadata(default(string)));
|
|
|
|
/// <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 方法
|
|
} |