-1

I have a button and want to pass multiple command parameter one being Binding and one is a constant string (in this case a constant string TDS)

I am trying to follow this link: Passing two command parameters using a WPF binding but this is for multibinding. In my case I am using 1 binding and one constant string. I tried the below but it is giving syntax error in VS.

<Button.CommandParameter>
    <MultiBinding>
        <Binding Path="."/>
        <s:String>TDS</s:String>
    </MultiBinding>
</Button.CommandParameter>

How do I fix this?

ASh
  • 34,632
  • 9
  • 60
  • 82
Tom
  • 33
  • 3

1 Answers1

2

Try this:

<Button.CommandParameter>
    <MultiBinding Converter="{StaticResource yourConverter}">
        <Binding Path="."/>
        <Binding>
            <Binding.Source>
                <s:String>TDS</s:String>
            </Binding.Source>
        </Binding>            
    </MultiBinding>
</Button.CommandParameter>

If your string is defined in resources you can reference it this way:

...
<x.Resources>
    <s:String x:Key="stringKey">TDS</s:String>
</x.Resources>
...
<Button.CommandParameter>
    <MultiBinding Converter="{StaticResource yourConverter}">
        <Binding Path="."/>
        <Binding Source="{StaticResource stringKey}" />       
    </MultiBinding>
</Button.CommandParameter>

As mentioned in the comment a converter must be specified for MultiBinding.

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • MultiBinding needs a Converter to produce a value. – Clemens Jan 29 '21 at 11:09
  • @Clemens Yes, I know. Not clear if it's copy paste error in question because in linked SO answer the converter is not missing. – user2250152 Jan 29 '21 at 11:14
  • thanks it worked. I know converter was missing. I just wanted to fix the compile time error first. Your answer is perfect. – Tom Jan 29 '21 at 11:48