a selective dual command binding converter in WPF?

Posted by Jippers on Stack Overflow See other posts from Stack Overflow or by Jippers
Published on 2010-05-14T16:20:13Z Indexed on 2010/05/14 16:24 UTC
Read the original article Hit count: 329

Filed under:
|
|
|

I'll start off and say I am not using the MVVM pattern for my WPF app. Please forgive me.

Right now I have a data template with two buttons, each binds to a different command on the CLR object this data template represents. Both use the same command parameter. Here's an example of the buttons.

<Button x:Name="Button1"
        Command="{Binding Path=Command1}"
        CommandParameter="{Binding Path=Text, ElementName=TextBox1}"
/>
<Button x:Name="Button2"
        Command="{Binding Path=Command2}"
        CommandParameter="{Binding Path=Text, ElementName=TextBox1}"
/>

I would like to refactor this into a single button that can perform either command based on a user setting like a boolean in Settings.settings. I don't have access to refactoring the CLR object itself. Also this is a Data Template there isn't codebehind for me to work with. My take is that a converter would be the best bet, but I don't know how I would put that together.

The converter would need to take in the CommandParameter, as well as the DataContext so it knows which object to execute the Commands on.

Can someone lend me a hand with this? Thanks in advance.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about command