This commit is contained in:
艾竹
2023-03-15 23:05:41 +08:00
parent 70dac7d41c
commit d97938cc2b
8 changed files with 113 additions and 39 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -18,11 +20,48 @@ namespace AIStudio.Wpf.Mind.Controls
/// <summary>
/// LinkControl.xaml 的交互逻辑
/// </summary>
public partial class LinkControl : UserControl
[TemplatePart(Name = "PART_InnerHyperlink", Type = typeof(Hyperlink))]
public class LinkControl : Control
{
public LinkControl()
public static readonly DependencyProperty UrlProperty =
DependencyProperty.Register(nameof(Url), typeof(string), typeof(LinkControl));
[Category("Common Properties"), Bindable(true)]
public string Url
{
InitializeComponent();
get
{
return GetValue(UrlProperty) as string;
}
set
{
SetValue(UrlProperty, value);
}
}
static LinkControl()
{
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(
typeof(LinkControl),
new FrameworkPropertyMetadata(typeof(LinkControl)));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
Hyperlink innerHyperlink = GetTemplateChild("PART_InnerHyperlink") as Hyperlink;
if (innerHyperlink != null)
{
innerHyperlink.Click += new RoutedEventHandler(InnerHyperlink_Click);
}
}
void InnerHyperlink_Click(object sender, RoutedEventArgs e)
{
// 激活的是当前默认的浏览器
Process.Start("explorer.exe", Url);
}
}
}