using System.Diagnostics; // ReSharper disable once CheckNamespace namespace WPFluent.Controls; /// /// Button that opens a URL in a web browser. /// public class HyperlinkButton : Button { /// /// Identifies the dependency property. /// 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); } } /// /// Gets or sets the URL (or application shortcut) to open. /// public string NavigateUri { get => GetValue(NavigateUriProperty) as string ?? string.Empty; set => SetValue(NavigateUriProperty, value); } }