You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace BPA.UIControl
  16. {
  17. /// <summary>
  18. /// 标签
  19. /// </summary>
  20. public class Tag : ContentControl
  21. {
  22. static Tag()
  23. {
  24. DefaultStyleKeyProperty.OverrideMetadata(typeof(Tag), new FrameworkPropertyMetadata(typeof(Tag)));
  25. }
  26. /// <inheritdoc/>
  27. public override void OnApplyTemplate()
  28. {
  29. base.OnApplyTemplate();
  30. this.MouseLeftButtonDown += Tag_MouseLeftButtonDown;
  31. }
  32. #region 属性
  33. /// <summary>
  34. /// 标题
  35. /// </summary>
  36. public static readonly DependencyProperty HeaderProperty =
  37. DependencyProperty.Register("Header", typeof(object), typeof(Tag), new PropertyMetadata(default(object)));
  38. /// <summary>
  39. /// 标题
  40. /// </summary>
  41. public object Header
  42. {
  43. get { return (object)GetValue(HeaderProperty); }
  44. set { SetValue(HeaderProperty, value); }
  45. }
  46. /// <summary>
  47. /// 标题背景色
  48. /// </summary>
  49. public static readonly DependencyProperty HeadBackgroundProperty =
  50. DependencyProperty.Register("HeadBackground", typeof(Brush), typeof(Tag), new PropertyMetadata(default(Brush)));
  51. /// <summary>
  52. /// 标题背景色
  53. /// </summary>
  54. public Brush HeadBackground
  55. {
  56. get { return (Brush)GetValue(HeadBackgroundProperty); }
  57. set { SetValue(HeadBackgroundProperty, value); }
  58. }
  59. /// <summary>
  60. /// 标题前景色
  61. /// </summary>
  62. public static readonly DependencyProperty HeadForegroundProperty =
  63. DependencyProperty.Register("HeadForeground", typeof(Brush), typeof(Tag), new PropertyMetadata(default(Brush)));
  64. /// <summary>
  65. /// 标题前景色
  66. /// </summary>
  67. public Brush HeadForeground
  68. {
  69. get { return (Brush)GetValue(HeadForegroundProperty); }
  70. set { SetValue(HeadForegroundProperty, value); }
  71. }
  72. /// <summary>
  73. /// 链接
  74. /// </summary>
  75. public static readonly DependencyProperty UrlProperty =
  76. DependencyProperty.Register("Url", typeof(string), typeof(Tag), new PropertyMetadata(default(string)));
  77. /// <summary>
  78. /// 链接
  79. /// </summary>
  80. public string Url
  81. {
  82. get { return (string)GetValue(UrlProperty); }
  83. set { SetValue(UrlProperty, value); }
  84. }
  85. #endregion 属性
  86. #region 方法
  87. private void Tag_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  88. {
  89. if (!string.IsNullOrEmpty(Url))
  90. {
  91. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(Url) { UseShellExecute = true });
  92. }
  93. }
  94. #endregion 方法
  95. }
  96. }