Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass an empty string as a ConverterPararmeter?

Tags:

binding

wpf

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?

like image 931
Shimmy Weitzhandler Avatar asked Oct 30 '09 11:10

Shimmy Weitzhandler


3 Answers

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

<ContentControl Content="{Binding Converter={StaticResource someConverter}, ConverterParameter=''}" />
like image 96
CodeNaked Avatar answered Oct 20 '22 23:10

CodeNaked


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}}" />
like image 37
mjeanes Avatar answered Oct 20 '22 22:10

mjeanes


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.

like image 38
CMerat Avatar answered Oct 20 '22 23:10

CMerat