25
25
using Windows . UI . Xaml . Input ;
26
26
#endif
27
27
28
+ #if ! HAS_UNO_WINUI
29
+ namespace Uno . Toolkit . UI
30
+ {
31
+
32
+ // Dummy enum for Uno.UI v5 so ReturnType DP compiles as InputReturnType is available for v6+.
33
+ public enum InputReturnType
34
+ {
35
+ Default ,
36
+ Done ,
37
+ Go ,
38
+ Next ,
39
+ Search ,
40
+ Send
41
+ }
42
+ }
43
+ #endif
44
+
28
45
namespace Uno . Toolkit . UI
29
46
{
30
47
public static class InputExtensions
31
48
{
32
49
private static readonly ILogger _logger = typeof ( InputExtensions ) . Log ( ) ;
50
+
33
51
#region DependencyProperty: ReturnType
34
52
35
- #if HAS_UNO_WINUI
36
53
/// <summary>
37
54
/// Backing property for what type of return the soft keyboard will show.
38
55
/// </summary>
39
- public static DependencyProperty ReturnTypeProperty { get ; } =
40
- DependencyProperty . RegisterAttached (
56
+ public static DependencyProperty ReturnTypeProperty { [ DynamicDependency ( nameof ( GetReturnType ) ) ] get ; } = DependencyProperty . RegisterAttached (
41
57
"ReturnType" ,
42
58
typeof ( InputReturnType ) ,
43
59
typeof ( InputExtensions ) ,
44
60
new PropertyMetadata ( InputReturnType . Default , OnReturnTypeChanged ) ) ;
45
61
46
- public static InputReturnType GetReturnType ( DependencyObject obj ) =>
47
- ( InputReturnType ) obj . GetValue ( ReturnTypeProperty ) ;
62
+ [ DynamicDependency ( nameof ( SetReturnType ) ) ]
63
+ public static InputReturnType GetReturnType ( DependencyObject obj ) => ( InputReturnType ) obj . GetValue ( ReturnTypeProperty ) ;
64
+ [ DynamicDependency ( nameof ( GetReturnType ) ) ]
65
+ public static void SetReturnType ( DependencyObject obj , InputReturnType value ) => obj . SetValue ( ReturnTypeProperty , value ) ;
48
66
49
- public static void SetReturnType ( DependencyObject obj , InputReturnType value ) =>
50
- obj . SetValue ( ReturnTypeProperty , value ) ;
67
+ #endregion
51
68
52
69
private static void OnReturnTypeChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
53
70
{
71
+ #if HAS_UNO_WINUI
54
72
if ( sender is TextBox || sender is PasswordBox )
55
73
{
56
74
TextBoxExtensions . SetInputReturnType ( sender , ( InputReturnType ) e . NewValue ) ;
57
75
}
58
- }
59
76
#endif
77
+ }
60
78
61
- #endregion
62
79
#region DependencyProperty: AutoDismiss
63
80
64
- /// <summary>
65
- /// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed.
66
- /// </summary>
67
- public static DependencyProperty AutoDismissProperty
68
- {
69
- [ DynamicDependency ( nameof ( GetAutoDismiss ) ) ]
70
- get ;
71
- } = DependencyProperty . RegisterAttached (
81
+ /// <summary>
82
+ /// Backing property for whether the soft keyboard will be dismissed when the enter key is pressed.
83
+ /// </summary>
84
+ public static DependencyProperty AutoDismissProperty { [ DynamicDependency ( nameof ( GetAutoDismiss ) ) ] get ; } = DependencyProperty . RegisterAttached (
72
85
"AutoDismiss" ,
73
86
typeof ( bool ) ,
74
87
typeof ( InputExtensions ) ,
@@ -89,22 +102,16 @@ public static DependencyProperty AutoDismissProperty
89
102
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
90
103
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
91
104
/// </remarks>
92
- public static DependencyProperty AutoFocusNextProperty
93
- {
94
- [ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ]
95
- get ;
96
- } = DependencyProperty . RegisterAttached (
105
+ public static DependencyProperty AutoFocusNextProperty { [ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ] get ; } = DependencyProperty . RegisterAttached (
97
106
"AutoFocusNext" ,
98
107
typeof ( bool ) ,
99
108
typeof ( InputExtensions ) ,
100
109
new PropertyMetadata ( default ( bool ) , OnAutoFocusNextChanged ) ) ;
101
110
102
111
[ DynamicDependency ( nameof ( SetAutoFocusNext ) ) ]
103
112
public static bool GetAutoFocusNext ( DependencyObject obj ) => ( bool ) obj . GetValue ( AutoFocusNextProperty ) ;
104
-
105
113
[ DynamicDependency ( nameof ( GetAutoFocusNext ) ) ]
106
- public static void SetAutoFocusNext ( DependencyObject obj , bool value ) =>
107
- obj . SetValue ( AutoFocusNextProperty , value ) ;
114
+ public static void SetAutoFocusNext ( DependencyObject obj , bool value ) => obj . SetValue ( AutoFocusNextProperty , value ) ;
108
115
109
116
#endregion
110
117
#region DependencyProperty: AutoFocusNextElement
@@ -116,23 +123,16 @@ public static void SetAutoFocusNext(DependencyObject obj, bool value) =>
116
123
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
117
124
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
118
125
/// </remarks>
119
- public static DependencyProperty AutoFocusNextElementProperty
120
- {
121
- [ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ]
122
- get ;
123
- } = DependencyProperty . RegisterAttached (
126
+ public static DependencyProperty AutoFocusNextElementProperty { [ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ] get ; } = DependencyProperty . RegisterAttached (
124
127
"AutoFocusNextElement" ,
125
128
typeof ( DependencyObject ) ,
126
129
typeof ( InputExtensions ) ,
127
130
new PropertyMetadata ( default ( Control ) , OnAutoFocusNextElementChanged ) ) ;
128
131
129
132
[ DynamicDependency ( nameof ( SetAutoFocusNextElement ) ) ]
130
- public static Control GetAutoFocusNextElement ( DependencyObject obj ) =>
131
- ( Control ) obj . GetValue ( AutoFocusNextElementProperty ) ;
132
-
133
+ public static Control GetAutoFocusNextElement ( DependencyObject obj ) => ( Control ) obj . GetValue ( AutoFocusNextElementProperty ) ;
133
134
[ DynamicDependency ( nameof ( GetAutoFocusNextElement ) ) ]
134
- public static void SetAutoFocusNextElement ( DependencyObject obj , Control value ) =>
135
- obj . SetValue ( AutoFocusNextElementProperty , value ) ;
135
+ public static void SetAutoFocusNextElement ( DependencyObject obj , Control value ) => obj . SetValue ( AutoFocusNextElementProperty , value ) ;
136
136
137
137
#endregion
138
138
#if false // The property is now forwarded from CommandExtensions.Command
@@ -160,13 +160,10 @@ internal static bool IsEnterCommandSupportedFor(DependencyObject host)
160
160
161
161
private static void OnAutoDismissChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
162
162
=> UpdateSubscription ( sender ) ;
163
-
164
163
private static void OnAutoFocusNextChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
165
164
=> UpdateSubscription ( sender ) ;
166
-
167
165
private static void OnAutoFocusNextElementChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
168
166
=> UpdateSubscription ( sender ) ;
169
-
170
167
internal static void OnEnterCommandChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
171
168
=> UpdateSubscription ( sender ) ;
172
169
0 commit comments