Question

ribbon:Button CommandParameter binding issue

Posted 1 year ago by Avatar SledgeHammer01

Hi,

We're stuck on an older version (2011.1), but wanted to see if you had any input on this issue. We're using "by the book" MVVM, so we're binding controls to RelayCommandT:

 

<ribbon:Button ImageSourceSmall="/Demo;component/Resources/Delete16.png" ScreenTipHeader="Delete Server" Focusable="False"

Command="{Binding Path=DeleteCommand}" CommandParameter="{Binding ElementName=lbServers, Path=SelectedIndex}" />

 

My RelayCommandT is declared as a RelayCommandT<int>. The behavior we're seeing is:

 

1) CommandParameter = null / unbound - control sends a ICheckableCommandParameter structure in argument

2) CommandParameter hardcoded (i.e. "2", "xyz", etc) - control sends "2", "xyz" in argument as expected

3) *ISSUE* CommandParameter is bound as above = command is called ONCE with a ICheckableCommandParameter and SUBSEQUENT times with the correct bound value.

 

#3 is obviously an issue for RelayCommand<int>() if you are sending "the wrong datatype" one time. I do understand the nature of binding and have run into this issue myself as there is no way to know when "all bindings have been setup" as a control author, is there a work-around? I'm currently working around the issue by creating a RelayCommand<T1, T2> where I can specificy the CanExecute param differently then the ExecuteParam and I specify it as an object and check the type. Seems like the Tag parameter is not used for the ICheckableCommandParameter structure and I have to do something more verbose like:

 

<ribbon:Button.CommandParameter>

<ribbon:CheckableCommandParameter Tag="1" />

</ribbon:Button.CommandParameter>

 

Are there any other known workarounds that might be cleaner? These all seem kind of hacky :(.

 

Thanks!


Comments (1)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA

Hello,

Unfortunately what you are doing is probably the only way.  Or alternatively to change our RelayCommandT<int> to be a RelayCommandT<object>.  And in your command handler logic see if the paramter is of the type you know the command handles.  If so, cast it and continue.  You'd be excluding the second type param you have in your current workaround.  That's slightly less work in general.


Actipro Software Support
Information The latest build of this product (2018.1 build 0673) was released 1 month ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.