如何将带空格的字符串传递给converterParameter?

SSg*_*i88 23 c# wpf

我的示例代码如下.

我想传递'转到链接项' ConverterParameter但我不能,因为字符串有空格.

Text="{Binding Value, 
        Source={x:Static local:Dictionary.Instance}, 
        Converter={StaticResource StringConverter}, 
        ConverterParameter=Go to linked item, Mode=OneWay}"
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Cha*_*thJ 36

选项1

Text="{Binding Value, 
        Source={x:Static local:Dictionary.Instance}, 
        Converter={StaticResource StringConverter}, 
        ConverterParameter='Go to linked item', Mode=OneWay}"
Run Code Online (Sandbox Code Playgroud)

选项2

如果要在多个位置使用它,请添加字符串资源.

<sys:String x:Key="GoToLink">Go to linked item</sys:String>
Run Code Online (Sandbox Code Playgroud)

并传递资源键.

ConverterParameter={StaticResource ResourceKey=GoToLink}}
Run Code Online (Sandbox Code Playgroud)


mar*_*k_h 7

如果你的字符串有空格然后用单引号括起来,双引号将不起作用; 这可能是因为整个文本字段用双引号括起来,因此在绑定中再次使用它们会错误地指示闭包.

Text="{Binding Value, 
    Source={x:Static local:Dictionary.Instance}, 
    Converter={StaticResource StringConverter}, 
    ConverterParameter='Go to linked item', Mode=OneWay}"
Run Code Online (Sandbox Code Playgroud)