Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: change ControlExtensions to CommandExtensions #385

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/controls-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `Uno.Toolkit.UI` library adds the following controls:
The `Uno.Toolkit.UI` library adds the following helper classes:
- `SystemThemeHelper`: Provides a set of helper methods to check the current operating system theme, and manipulate the application dark/light theme.
- [`AncestorBinding` and `ItemsControlBinding`](helpers\ancestor-itemscontrol-binding.md): These markup extensions provides relative binding based on ancestor type. If you are familiar with WPF, they are very similar to `{RelativeSource Mode=FindAncestor}`.
- [`ControlExtensions`](helpers\control-extensions.md): Provides various attached properties for common controls.
- [`CommandExtensions`](helpers\command-extensions.md): Provides Command/CommandParameter attached properties for common scenarios.
kazo0 marked this conversation as resolved.
Show resolved Hide resolved
- [`InputExtensions`](helpers\input-extensions.md): Provides various attached properties for _input controls_, such as `TextBox` and `PasswordBox`.
- [`StatusBar`](helpers\StatusBar-extensions.md): Provides two attached properties on `Page` to controls the visual of the status bar on mobile platforms.
- [`TabBarItemExtensions`](helpers\TabBarItem-extensions.md): Provides additional features for `TabBarItem`.
Expand Down
10 changes: 5 additions & 5 deletions doc/helpers/control-extensions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ControlExtensions Attached Properties
Provides various attached properties for common controls.
# CommandExtensions Attached Properties
Provides Command/CommandParameter attached properties for common scenarios.

## Properties
Property|Type|Description
Expand All @@ -21,15 +21,15 @@ Command on `ListView`\*: [`IsItemClickEnabled`](https://docs.microsoft.com/en-us
## Usage
```xml
<!-- Execute command on enter -->
<PasswordBox utu:ControlExtensions.Command="{Binding Login}" />
<PasswordBox utu:CommandExtensions.Command="{Binding Login}" />

<!-- ListView item click-->
<ListView ItemsSource="123"
IsItemClickEnabled="True"
utu:ControlExtensions.Command="{Binding UpdateSelection}" />
utu:CommandExtensions.Command="{Binding UpdateSelection}" />

<!-- NavigationView item invoke -->
<NavigationView utu:ControlExtensions.Command="{Binding Navigate}">
<NavigationView utu:CommandExtensions.Command="{Binding Navigate}">
<NavigationView.MenuItems>
<NavigationViewItem Content="Apple" />
<NavigationViewItem Content="Banana" />
Expand Down
2 changes: 1 addition & 1 deletion doc/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
items:
- name: AncestorBinding and ItemsControlBinding
href: helpers/ancestor-itemscontrol-binding.md
- name: ControlExtensions attached properties
- name: CommandExtensions attached properties
href: helpers/control-extensions.md
- name: InputExtensions attached properties
href: helpers/input-extensions.md
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.ControlExtensionsSamplePage"
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.CommandExtensionsSamplePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -21,7 +21,7 @@
<StackPanel Spacing="8">
<TextBlock Text="- TextBox/PasswordBox enter key press:" />
<TextBlock Text="{Binding InputDebugText}" />
<TextBox utu:ControlExtensions.Command="{Binding DebugInputCommand}" />
<TextBox utu:CommandExtensions.Command="{Binding DebugInputCommand}" />
</StackPanel>

<!-- ListView[Command] example -->
Expand All @@ -30,7 +30,7 @@
<TextBlock Text="{Binding SelectionDebugText}" />
<ListView ItemsSource="123"
IsItemClickEnabled="True"
utu:ControlExtensions.Command="{Binding DebugSelectionCommand}">
utu:CommandExtensions.Command="{Binding DebugSelectionCommand}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock>Item #<Run Text="{Binding}" /></TextBlock>
Expand All @@ -43,7 +43,7 @@
<StackPanel>
<TextBlock Text="- NavigationView item invoke" />
<TextBlock Text="{Binding NavigationDebugText}" />
<NavigationView utu:ControlExtensions.Command="{Binding DebugNavigationCommand}">
<NavigationView utu:CommandExtensions.Command="{Binding DebugNavigationCommand}">
<NavigationView.MenuItems>
<NavigationViewItem Content="Apple" />
<NavigationViewItem Content="Banana" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

namespace Uno.Toolkit.Samples.Content.Controls
{
[SamplePage(SampleCategory.Behaviors, nameof(ControlExtensions), SourceSdk.UnoToolkit, DataType = typeof(ControlExtensionsSamplePageVM))]
public sealed partial class ControlExtensionsSamplePage : Page
[SamplePage(SampleCategory.Behaviors, nameof(CommandExtensions), SourceSdk.UnoToolkit, DataType = typeof(CommandExtensionsSamplePageVM))]
public sealed partial class CommandExtensionsSamplePage : Page
{
public ControlExtensionsSamplePage()
public CommandExtensionsSamplePage()
{
this.InitializeComponent();
}

public class ControlExtensionsSamplePageVM : ViewModelBase
public class CommandExtensionsSamplePageVM : ViewModelBase
{
public string InputDebugText { get => GetProperty<string>(); set => SetProperty(value); }
public string SelectionDebugText { get => GetProperty<string>(); set => SetProperty(value); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\ChipSamplePage.xaml.cs">
<DependentUpon>ChipSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\ControlExtensionsSamplePage.xaml.cs">
<DependentUpon>ControlExtensionsSamplePage.xaml</DependentUpon>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\CommandExtensionsSamplePage.xaml.cs">
<DependentUpon>CommandExtensionsSamplePage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Content\Controls\DrawerFlyoutSamplePage.xaml.cs">
<DependentUpon>DrawerFlyoutSamplePage.xaml</DependentUpon>
Expand Down Expand Up @@ -212,7 +212,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\ControlExtensionsSamplePage.xaml">
<Page Include="$(MSBuildThisFileDirectory)Content\Controls\CommandExtensionsSamplePage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

namespace Uno.Toolkit.UI
{
public static class ControlExtensions
public static class CommandExtensions
{
private static ILogger _logger = typeof(ControlExtensions).Log();
private static ILogger _logger = typeof(CommandExtensions).Log();

#region DependencyProperty: Command

Expand All @@ -43,7 +43,7 @@ public static class ControlExtensions
public static DependencyProperty CommandProperty { get; } = DependencyProperty.RegisterAttached(
"Command",
typeof(ICommand),
typeof(ControlExtensions),
typeof(CommandExtensions),
new PropertyMetadata(default(ICommand), OnCommandChanged));

public static ICommand GetCommand(DependencyObject obj) => (ICommand)obj.GetValue(CommandProperty);
Expand All @@ -58,7 +58,7 @@ public static class ControlExtensions
public static DependencyProperty CommandParameterProperty { get; } = DependencyProperty.RegisterAttached(
"CommandParameter",
typeof(object),
typeof(ControlExtensions),
typeof(CommandExtensions),
new PropertyMetadata(default(object)));

public static object GetCommandParameter(DependencyObject obj) => (object)obj.GetValue(CommandParameterProperty);
Expand Down Expand Up @@ -98,7 +98,7 @@ private static void OnCommandChanged(DependencyObject sender, DependencyProperty
{
if (_logger.IsEnabled(LogLevel.Warning))
{
_logger.Warn($"ControlExtensions.Command is not supported on '{sender.GetType().FullName}'.");
_logger.Warn($"CommandExtensions.Command is not supported on '{sender.GetType().FullName}'.");
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Uno.Toolkit.UI/Behaviors/InputExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static class InputExtensions
public static void SetAutoFocusNextElement(DependencyObject obj, Control value) => obj.SetValue(AutoFocusNextElementProperty, value);

#endregion
#if false // The property is now forwarded from ControlExtensions.Command
#if false // The property is now forwarded from CommandExtensions.Command
#region DependencyProperty: EnterCommand

public static DependencyProperty EnterCommandProperty { get; } = DependencyProperty.RegisterAttached(
Expand All @@ -95,7 +95,7 @@ public static class InputExtensions
#endif

/// <summary>
/// Check if InputExtensions contains the <see cref="ControlExtensions.CommandProperty" /> implementations for <paramref name="host"/>.
/// Check if InputExtensions contains the <see cref="CommandExtensions.CommandProperty" /> implementations for <paramref name="host"/>.
/// </summary>
internal static bool IsEnterCommandSupportedFor(DependencyObject host)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ bool GetIsBehaviorActive() =>
GetAutoDismiss(sender) ||
GetAutoFocusNext(sender) ||
GetAutoFocusNextElement(sender) != null ||
ControlExtensions.GetCommand(sender) != null;
CommandExtensions.GetCommand(sender) != null;
}

private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
Expand All @@ -139,9 +139,9 @@ private static void OnUIElementKeyUp(object sender, KeyRoutedEventArgs e)
if (e.Key != VirtualKey.Enter) return;

// handle enter command
var command = ControlExtensions.GetCommand(host);
var command = CommandExtensions.GetCommand(host);
if (command != null &&
(ControlExtensions.GetCommandParameter(host) ?? GetInputParameter()) is var parameter &&
(CommandExtensions.GetCommandParameter(host) ?? GetInputParameter()) is var parameter &&
command.CanExecute(parameter))
{
command.Execute(parameter);
Expand Down
1 change: 1 addition & 0 deletions src/Uno.Toolkit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Root", "_Root", "{BA0C538E
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
PlatformItemGroups.props = PlatformItemGroups.props
..\README.md = ..\README.md
Uno.CrossTargeting.props = Uno.CrossTargeting.props
EndProjectSection
Expand Down