Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass string with spaces to converterParameter?

Tags:

c#

wpf

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?

like image 357
SSgi88 Avatar asked Sep 09 '15 04:09

SSgi88


2 Answers

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}}
like image 106
CharithJ Avatar answered Nov 14 '22 15:11

CharithJ


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}"
like image 9
mark_h Avatar answered Nov 14 '22 13:11

mark_h