fsprojects / FsXaml

F# Tools for working with XAML Projects
http://fsprojects.github.io/FsXaml/
MIT License
171 stars 48 forks source link

EventToCommand: parameter contains PassEventArgsToCommand flag #78

Open FoggyFinder opened 5 years ago

FoggyFinder commented 5 years ago

To retrieve the data that was passed via command parameter one have to use additional steps.

For example:

<fsxaml:EventToCommand Command="{Binding DataContext.SomeMsg, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}" CommandParameter="{Binding SomeProp}" />
<@ vm.SomeMsg @> |> Bind.cmdParam (unbox<obj*bool> >> fst >> string >> Messages.SomeMsg)

because getParameter function looks like:

let getParameter (param : obj) =
    match self.CommandParameter, self.PassEventArgsToCommand with
    | (null, true) -> self.EventArgsConverter.Convert (param :?> EventArgs) self.EventArgsConverterParameter
    | param -> param :> obj 

maybe it will be better to not include self.PassEventArgsToCommand in the second case? like

let getParameter (param : obj) =
    match self.CommandParameter, self.PassEventArgsToCommand with
    | (null, true) -> self.EventArgsConverter.Convert (param :?> EventArgs) self.EventArgsConverterParameter
    | p, _ -> p 

Then it will be consist with docs:

The paramter passed to the ICommand. If this is set, the EventArgs are ignored