将自定义字符串添加到 xaml 中的字符串依赖项 属性

Adding custom string to string dependency property in xaml

我有一个 DependencyProperty 名称作为字符串。是否可以将此 属性 与 XAML 中的自定义字符串一起使用?像这样:

<MyControl.Text>
    <MultiBinding StringFormat="{}{0}{1}">
        <Binding Source="{Binding Name}" />
        <Binding Source="Custom Text" />
    </MultiBinding>
</MyControl.Text>

而不是 MultiBindingCustom Text 附加到 StringFormat

Text="{Binding Path=Name, StringFormat='{}{0} custom text'}"

如果文本包含 {},那么它们也应该被转义。

xaml 编辑器将它们解释为标记扩展,因此将 { 更改为 \{

转换器将 {} 解释为参数的位置,因此双括号 {{}}

StringFormat='\{0} custom \{\{}} text'