Commands for Controls Without a Command Property

Problem

Current controls may not always provide a Command property to bind to an ICommand in XAML. This can make it difficult to invoke commands in response to user interactions such as when a TextBox/PasswordBox enter key is pressed, a ListViewBase's ItemClick is fired, NavigationView.ItemInvoked, or an ItemsRepeater item is tapped.

Solution

The CommandExtensions class in the Uno Toolkit provides Command/CommandParameter attached properties for common scenarios.

PasswordBox Enter Key

<PasswordBox x:Name="LoginPassword"
             utu:InputExtensions.ReturnType="Done"
             utu:CommandExtensions.Command="{Binding Login}"
Tip

Usage on TextBox/PasswordBox will also cause the keyboard dismiss on enter. Similar to the InputExtensions.AutoDismiss behavior, which is explained in the InputExtensions documentation.

ItemsRepeater Item Tapped

<muxc:ItemsRepeater ItemsSource="{Binding Data}"
                    utu:CommandExtensions.Command="{Binding Parent.CategorySearch}">

Source Code

Documentation