9
9
namespace Microsoft . Toolkit . Uwp . UI
10
10
{
11
11
/// <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
13
13
/// it to invoke a <see cref="ICommand"/> when clicked
14
14
/// </summary>
15
15
public static class HyperlinkExtensions
@@ -29,64 +29,51 @@ public static class HyperlinkExtensions
29
29
/// </summary>
30
30
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> from which to get the associated <see cref="ICommand"/> instance</param>
31
31
/// <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 ) ;
36
33
37
34
/// <summary>
38
35
/// Sets the <see cref="ICommand"/> instance assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
39
36
/// </summary>
40
37
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> to associated the <see cref="ICommand"/> instance to</param>
41
38
/// <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 ) ;
46
40
47
41
/// <summary>
48
42
/// Gets the <see cref="CommandProperty"/> instance assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
49
43
/// </summary>
50
44
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> from which to get the associated <see cref="CommandProperty"/> value</param>
51
45
/// <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 ) ;
56
47
57
48
/// <summary>
58
49
/// Sets the <see cref="CommandProperty"/> assocaited with the specified <see cref="Windows.UI.Xaml.Documents.Hyperlink"/>
59
50
/// </summary>
60
51
/// <param name="obj">The <see cref="Windows.UI.Xaml.Documents.Hyperlink"/> to associated the <see cref="CommandProperty"/> instance to</param>
61
52
/// <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 ) ;
66
54
67
55
private static void OnCommandPropertyChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs args )
68
56
{
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 )
72
58
{
73
59
hyperlink . Click -= OnHyperlinkClicked ;
74
60
75
- ICommand command = args . NewValue as ICommand ;
76
-
77
- if ( command != null )
61
+ if ( args . NewValue is ICommand )
78
62
{
79
63
hyperlink . Click += OnHyperlinkClicked ;
80
64
}
81
65
}
82
66
}
83
67
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 )
85
69
{
86
- ICommand command = GetCommand ( sender ) ;
87
- object parameter = GetCommandParameter ( sender ) ;
70
+ var command = GetCommand ( sender ) ;
71
+ var parameter = GetCommandParameter ( sender ) ;
88
72
89
- command ? . Execute ( parameter ) ;
73
+ if ( command ? . CanExecute ( parameter ) == true )
74
+ {
75
+ command . Execute ( parameter ) ;
76
+ }
90
77
}
91
78
}
92
79
}
0 commit comments