XAML中的String.Format没有绑定

时间:2018-06-01 09:59:35

标签: wpf xaml

我需要连接一些字符串的各种组合,如下所示:

"After doing this and that, press the 'whatever'-button."

有多种可能的组合,为了保证将来安全,我想做某种

String.Format("After doing this and that, press the '{0}'-button.", "whatever");

使用字符串资源中的字符串。

我发现的只有:

<!-- Strings.Temperature contains: "Temperature: {0} °C" --> 
Text="{Binding Temperature, StringFormat={x:Static loc:Strings.Temperature}}" />

甚至:

<TextBlock.Text>
    <!-- Strings.Temperature contains: "Temperature: {0} °C / {1} °F" --> 
    <MultiBinding StringFormat=StringFormat={x:Static loc:Strings.Temperature}>
        <Binding Path="{Binding TemperatureCelcius}" />
        <Binding Path="{Binding TemperatureFahrenheit}" />
    </MultiBinding>
</TextBlock.Text>

但我没有约束&#34;价值&#34;串。它也是一个静态变量。而且我知道我可以将它绑定到某个viewmodel字符串属性,但我不想在不同的视图模型中产生如此多的开销。

有什么想法吗?

0 个答案:

没有答案