diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Hyperlink/HyperlinkExtensions.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Hyperlink/HyperlinkExtensions.cs index 39c346a9be8..e4697182b60 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Hyperlink/HyperlinkExtensions.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Hyperlink/HyperlinkExtensions.cs @@ -9,7 +9,7 @@ namespace Microsoft.Toolkit.Uwp.UI { /// - /// Provides attached dependency properties for the content element that allows + /// Provides attached dependency properties for the content element that allows /// it to invoke a when clicked /// public static class HyperlinkExtensions @@ -29,64 +29,51 @@ public static class HyperlinkExtensions /// /// The from which to get the associated instance /// The instance associated with the the or null - public static ICommand GetCommand(Windows.UI.Xaml.Documents.Hyperlink obj) - { - return (ICommand)obj.GetValue(CommandProperty); - } + public static ICommand GetCommand(Hyperlink obj) => (ICommand)obj.GetValue(CommandProperty); /// /// Sets the instance assocaited with the specified /// /// The to associated the instance to /// The instance to bind to the - public static void SetCommand(Windows.UI.Xaml.Documents.Hyperlink obj, ICommand value) - { - obj.SetValue(CommandProperty, value); - } + public static void SetCommand(Hyperlink obj, ICommand value) => obj.SetValue(CommandProperty, value); /// /// Gets the instance assocaited with the specified /// /// The from which to get the associated value /// The value associated with the the or null - public static object GetCommandParameter(Windows.UI.Xaml.Documents.Hyperlink obj) - { - return obj.GetValue(CommandParameterProperty); - } + public static object GetCommandParameter(Hyperlink obj) => obj.GetValue(CommandParameterProperty); /// /// Sets the assocaited with the specified /// /// The to associated the instance to /// The to set the to - public static void SetCommandParameter(Windows.UI.Xaml.Documents.Hyperlink obj, object value) - { - obj.SetValue(CommandParameterProperty, value); - } + public static void SetCommandParameter(Hyperlink obj, object value) => obj.SetValue(CommandParameterProperty, value); private static void OnCommandPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { - Windows.UI.Xaml.Documents.Hyperlink hyperlink = sender as Windows.UI.Xaml.Documents.Hyperlink; - - if (hyperlink != null) + if (sender is Hyperlink hyperlink) { hyperlink.Click -= OnHyperlinkClicked; - ICommand command = args.NewValue as ICommand; - - if (command != null) + if (args.NewValue is ICommand) { hyperlink.Click += OnHyperlinkClicked; } } } - private static void OnHyperlinkClicked(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args) + private static void OnHyperlinkClicked(Hyperlink sender, HyperlinkClickEventArgs args) { - ICommand command = GetCommand(sender); - object parameter = GetCommandParameter(sender); + var command = GetCommand(sender); + var parameter = GetCommandParameter(sender); - command?.Execute(parameter); + if (command?.CanExecute(parameter) == true) + { + command.Execute(parameter); + } } } }