Skip to content

Commit 1cbcf90

Browse files
committed
Merge remote-tracking branch 'origin/master' into u/vgromfeld/removeUnusedFields
2 parents d203d0a + abf77ed commit 1cbcf90

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/Hyperlink/HyperlinkExtensions.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace Microsoft.Toolkit.Uwp.UI
1010
{
1111
/// <summary>
12-
/// Provides attached dependency properties for the <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> content element that allows
12+
/// Provides attached dependency properties for the <see cref="Hyperlink"/> content element that allows
1313
/// it to invoke a <see cref="ICommand"/> when clicked
1414
/// </summary>
1515
public static class HyperlinkExtensions
@@ -29,64 +29,51 @@ public static class HyperlinkExtensions
2929
/// </summary>
3030
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> from which to get the associated <see cref="ICommand"/> instance</param>
3131
/// <returns>The <see cref="ICommand"/> instance associated with the the <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> or null</returns>
32-
public static ICommand GetCommand(Windows.UI.Xaml.Documents.Hyperlink obj)
33-
{
34-
return (ICommand)obj.GetValue(CommandProperty);
35-
}
32+
public static ICommand GetCommand(Hyperlink obj) => (ICommand)obj.GetValue(CommandProperty);
3633

3734
/// <summary>
3835
/// Sets the <see cref="ICommand"/> instance assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
3936
/// </summary>
4037
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> to associated the <see cref="ICommand"/> instance to</param>
4138
/// <param name="value">The <see cref="ICommand"/> instance to bind to the <see cref="Windows.UI.Xaml.Documents.Hyperlink"/></param>
42-
public static void SetCommand(Windows.UI.Xaml.Documents.Hyperlink obj, ICommand value)
43-
{
44-
obj.SetValue(CommandProperty, value);
45-
}
39+
public static void SetCommand(Hyperlink obj, ICommand value) => obj.SetValue(CommandProperty, value);
4640

4741
/// <summary>
4842
/// Gets the <see cref="CommandProperty"/> instance assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
4943
/// </summary>
5044
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> from which to get the associated <see cref="CommandProperty"/> value</param>
5145
/// <returns>The <see cref="CommandProperty"/> value associated with the the <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> or null</returns>
52-
public static object GetCommandParameter(Windows.UI.Xaml.Documents.Hyperlink obj)
53-
{
54-
return obj.GetValue(CommandParameterProperty);
55-
}
46+
public static object GetCommandParameter(Hyperlink obj) => obj.GetValue(CommandParameterProperty);
5647

5748
/// <summary>
5849
/// Sets the <see cref="CommandProperty"/> assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
5950
/// </summary>
6051
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> to associated the <see cref="CommandProperty"/> instance to</param>
6152
/// <param name="value">The <see cref="object"/> to set the <see cref="CommandProperty"/> to</param>
62-
public static void SetCommandParameter(Windows.UI.Xaml.Documents.Hyperlink obj, object value)
63-
{
64-
obj.SetValue(CommandParameterProperty, value);
65-
}
53+
public static void SetCommandParameter(Hyperlink obj, object value) => obj.SetValue(CommandParameterProperty, value);
6654

6755
private static void OnCommandPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
6856
{
69-
Windows.UI.Xaml.Documents.Hyperlink hyperlink = sender as Windows.UI.Xaml.Documents.Hyperlink;
70-
71-
if (hyperlink != null)
57+
if (sender is Hyperlink hyperlink)
7258
{
7359
hyperlink.Click -= OnHyperlinkClicked;
7460

75-
ICommand command = args.NewValue as ICommand;
76-
77-
if (command != null)
61+
if (args.NewValue is ICommand)
7862
{
7963
hyperlink.Click += OnHyperlinkClicked;
8064
}
8165
}
8266
}
8367

84-
private static void OnHyperlinkClicked(Windows.UI.Xaml.Documents.Hyperlink sender, Windows.UI.Xaml.Documents.HyperlinkClickEventArgs args)
68+
private static void OnHyperlinkClicked(Hyperlink sender, HyperlinkClickEventArgs args)
8569
{
86-
ICommand command = GetCommand(sender);
87-
object parameter = GetCommandParameter(sender);
70+
var command = GetCommand(sender);
71+
var parameter = GetCommandParameter(sender);
8872

89-
command?.Execute(parameter);
73+
if (command?.CanExecute(parameter) == true)
74+
{
75+
command.Execute(parameter);
76+
}
9077
}
9178
}
9279
}

0 commit comments

Comments
 (0)