Skip to content

Commit

Permalink
chore: warning & xml documentation (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Aug 24, 2022
1 parent cdd407c commit 4b0a92b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Uno.Toolkit.UI/Behaviors/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public static class ControlExtensions

#region DependencyProperty: Command

/// <summary>
/// Backing property for the command to execute when <see cref="TextBox"/>/<see cref="PasswordBox"/> enter key is pressed, <see cref="ListViewBase.ItemClick" /> and <see cref="NavigationView.ItemInvoked"/>.
/// </summary>
/// <remarks>
/// For Command, the relevant parameter is also provided for the <see cref="ICommand.CanExecute(object)"/> and <see cref="ICommand.Execute(object)"/> call:
/// <list type="bullet">
/// <item><see cref="TextBox.Text"/></item>
/// <item><see cref="PasswordBox.Password"/></item>
/// <item><see cref="ItemClickEventArgs.ClickedItem"/> from <see cref="ListViewBase.ItemClick"/></item>
/// <item><see cref="NavigationViewItemInvokedEventArgs.InvokedItem"/> from <see cref="NavigationView.ItemInvoked"/> </item>
/// </list>
/// Unless <see cref="CommandParameterProperty"/> is set, which replaces the above.
/// </remarks>
public static DependencyProperty CommandProperty { get; } = DependencyProperty.RegisterAttached(
"Command",
typeof(ICommand),
Expand All @@ -39,6 +52,9 @@ public static class ControlExtensions
#endregion
#region DependencyProperty: CommandParameter

/// <summary>
/// Backing property for the parameter to pass to the <see cref="CommandProperty"/>.
/// </summary>
public static DependencyProperty CommandParameterProperty { get; } = DependencyProperty.RegisterAttached(
"CommandParameter",
typeof(object),
Expand Down Expand Up @@ -78,6 +94,13 @@ private static void OnCommandChanged(DependencyObject sender, DependencyProperty
nv.ItemInvoked += OnNavigationViewItemInvoked;
}
}
else
{
if (_logger.IsEnabled(LogLevel.Warning))
{
_logger.Warn($"ControlExtensions.Command is not supported on '{sender.GetType().FullName}'.");
}
}
}

private static void OnListViewItemClick(object sender, ItemClickEventArgs e)
Expand Down
31 changes: 30 additions & 1 deletion src/Uno.Toolkit.UI/Behaviors/InputExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Extensions.Logging;
using Uno.Extensions;
using Uno.Logging;
using Windows.System;
using Windows.UI.ViewManagement;

Expand All @@ -21,8 +24,13 @@ namespace Uno.Toolkit.UI
{
public static class InputExtensions
{
private static readonly ILogger _logger = typeof(InputExtensions).Log();

#region DependencyProperty: AutoDismiss

/// <summary>
/// Backing property for whether the soft-keyboard will be dismissed when the enter key is pressed.
/// </summary>
public static DependencyProperty AutoDismissProperty { get; } = DependencyProperty.RegisterAttached(
"AutoDismiss",
typeof(bool),
Expand All @@ -35,6 +43,13 @@ public static class InputExtensions
#endregion
#region DependencyProperty: AutoFocusNext

/// <summary>
/// Backing property for whether the focus will move to the next focusable element when the enter key is pressed.
/// </summary>
/// <remarks>
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
/// </remarks>
public static DependencyProperty AutoFocusNextProperty { get; } = DependencyProperty.RegisterAttached(
"AutoFocusNext",
typeof(bool),
Expand All @@ -47,6 +62,13 @@ public static class InputExtensions
#endregion
#region DependencyProperty: AutoFocusNextElement

/// <summary>
/// Sets the next control to focus when the enter key is pressed.
/// </summary>
/// <remarks>
/// Having either or both of the <see cref="AutoFocusNextProperty"/> and <see cref="AutoFocusNextElementProperty"/> set will enable the focus next behavior.
/// AutoFocusNextElement will take precedences over AutoFocusNext when both are set.
/// </remarks>
public static DependencyProperty AutoFocusNextElementProperty { get; } = DependencyProperty.RegisterAttached(
"AutoFocusNextElement",
typeof(DependencyObject),
Expand Down Expand Up @@ -87,7 +109,7 @@ internal static bool IsEnterCommandSupportedFor(DependencyObject host)

private static void UpdateSubscription(DependencyObject sender)
{
if (sender is Control control && IsEnterCommandSupportedFor(sender))
if (sender is Control control && (sender is TextBox || sender is PasswordBox))
{
// note: on android, UIElement.KeyUp and Control.KeyUp are not the same event, and the UIElement one doesnt work.
control.KeyUp -= OnUIElementKeyUp;
Expand All @@ -96,6 +118,13 @@ private static void UpdateSubscription(DependencyObject sender)
control.KeyUp += OnUIElementKeyUp;
}
}
else
{
if (_logger.IsEnabled(LogLevel.Warning))
{
_logger.Warn($"This property is not supported on '{sender.GetType().FullName}'.");
}
}

bool GetIsBehaviorActive() =>
GetAutoDismiss(sender) ||
Expand Down

0 comments on commit 4b0a92b

Please sign in to comment.