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