microsoft / xaml-standard

XAML Standard : a set of principles that drive XAML dialect alignment
Other
805 stars 50 forks source link

Add CommandParameter to Button #191

Open Daniel-Svensson opened 7 years ago

Daniel-Svensson commented 7 years ago

The current draft includes support for the Command property on button, I would like to also se the CommandParamter property.

Why

Availability UWP, Xamarin, WPF, Silverlight

Examples `

monkeynoises commented 7 years ago

Provide the ability to support multiple parameters. Here's a proposal:

CommandParameters="{Binding SelectedXXX}{Binding OtherProperty}{x:Int 1}{x:String foo}"

The ICommandSource interface would look something like this:

   interface ICommandSource
    {
        ICommand Command { get; }

        object CommandParameter { get; }

        object []CommandParameters { get; }

        IInputElement CommandTarget { get; }

        object this[int index]
        {
            get;
            set;
        }
    }

CommandParameter would just be an alias for accessing the first parameter in code behind (so as not to break existing code).....(or just deprecate CommandParameter entirely, and make CommandParameters the default for single and multiple parameters).

The indexer just makes it a bit more natural to access the parameters through the interface.

Literals could be specified by using the "type".

Element syntax would be:

<Thing.CommandParameters>
<Binding Path="SelectedXXX"/>
<Binding Path="OtherProperty"/>
<x:Int>1</x:Int>
<x:String>foo</x:String>
</Thing.CommandParameters>
Odonno commented 7 years ago

It is sure we should add CommandParameter as it is already implemented in WPF, UWP or even Xamarin.

I am also interested by the proposal of @monkeynoises, I think the Command pattern of MVVM should be more flexible by allowing multiple parameters for example.

swythan commented 6 years ago

If you could get the WPF team to fix their Button implementation to re-evaluate the Command's CanExecute when the CommanParameter changes, that would also be helpful. That was logged (in Connect) as bug in WPF years ago.