Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104781

How to pass an empty string as a ConverterPararmeter?

Hello I have a Binding that I am using along with a converter, I want the parameter that is transferred to the converter should be an empty string. Is there a way I can pass it via an inline binding?

Upvotes: 5

Views: 2662

Answers (3)

CodeNaked
CodeNaked

Reputation: 41403

You can actually use single quotes inline to pass an empty string, like so:

<ContentControl Content="{Binding Converter={StaticResource someConverter}, ConverterParameter=''}" />

Upvotes: 8

mjeanes
mjeanes

Reputation: 1626

If you want to do it inline, you can use the static String.Empty property. You need to add a namespace definition for clr-namespace:System to use it.

In your Window definition (or whichever control you're using):

xmlns:System="clr-namespace:System;assembly=mscorlib"

Then you can use something like this:

<ContentControl Content="{Binding Converter={StaticResource someConverter}, ConverterParameter={x:Static System:String.Empty}}" />

Upvotes: 8

Christian Merat
Christian Merat

Reputation: 4314

Instead of defining the binding in a single line:

<Control Binding={Property, Converter={StaticResource someConverter}, ConverterParameter={StaticResource someParameter}} />

You can define it multi-line and specify attributes individually:

<Control>
    <Control.Binding>
        <Binding Path="Property" Converter="{StaticResource someConverter}" ConverterParameter="" />
    </Control.Binding>
</Control>

Pretty sure that'll do what you're looking for.

Upvotes: 2

Related Questions