Files
Shrlalgo.RvKits/WPFluent/Controls/HyperlinkButton/HyperlinkButton.cs
2025-04-24 20:56:44 +08:00

55 lines
1.3 KiB
C#

using System.Diagnostics;
// ReSharper disable once CheckNamespace
namespace WPFluent.Controls;
/// <summary>
/// Button that opens a URL in a web browser.
/// </summary>
public class HyperlinkButton : Button
{
/// <summary>
/// Identifies the <see cref="NavigateUri"/> dependency property.
/// </summary>
public static readonly DependencyProperty NavigateUriProperty = DependencyProperty.Register(
nameof(NavigateUri),
typeof(string),
typeof(HyperlinkButton),
new PropertyMetadata(string.Empty));
protected override void OnClick()
{
base.OnClick();
if(string.IsNullOrEmpty(NavigateUri))
{
return;
}
try
{
Debug.WriteLine(
$"INFO | HyperlinkButton clicked, with href: {NavigateUri}",
"WPFluent.HyperlinkButton");
ProcessStartInfo sInfo = new(new Uri(NavigateUri).AbsoluteUri) { UseShellExecute = true };
Process.Start(sInfo);
} catch(Exception e)
{
Debug.WriteLine(e);
}
}
/// <summary>
/// Gets or sets the URL (or application shortcut) to open.
/// </summary>
public string NavigateUri
{
get => GetValue(NavigateUriProperty) as string ?? string.Empty;
set => SetValue(NavigateUriProperty, value);
}
}