SSgi88
SSgi88

Reputation: 293

How do I pass string with spaces to converterParameter?

My sample code is below.

I want to pass 'Go to linked item' to ConverterParameter but I can't because the string has spaces.

Text="{Binding Value, 
        Source={x:Static local:Dictionary.Instance}, 
        Converter={StaticResource StringConverter}, 
        ConverterParameter=Go to linked item, Mode=OneWay}"

How can I do this?

Upvotes: 28

Views: 19881

Answers (2)

mark_h
mark_h

Reputation: 5477

If your string has spaces then wrap it in single quotes, double quotes won't work; this is probably due to the fact that the entire text field is wrapped in double quotes and so using them again within the binding would incorrectly indicate closure.

Text="{Binding Value, 
    Source={x:Static local:Dictionary.Instance}, 
    Converter={StaticResource StringConverter}, 
    ConverterParameter='Go to linked item', Mode=OneWay}"

Upvotes: 9

CharithJ
CharithJ

Reputation: 47570

Option 1

Text="{Binding Value, 
        Source={x:Static local:Dictionary.Instance}, 
        Converter={StaticResource StringConverter}, 
        ConverterParameter='Go to linked item', Mode=OneWay}"

Option 2

If you want to use this in multiple places add a string resource.

<sys:String x:Key="GoToLink">Go to linked item</sys:String>

And pass the resource key.

ConverterParameter={StaticResource ResourceKey=GoToLink}}

Upvotes: 51

Related Questions