开发者

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?


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

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


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}}" />


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜