C#中的Concat数据绑定和静态文本

Gle*_*enn 7 c# data-binding

所以我有一个带有数据绑定的文本框,但我想在我的xaml代码中添加静态文本.

<TextBlock Text="{Binding Preptime}"></TextBlock>
Run Code Online (Sandbox Code Playgroud)

这只会显示分钟数,我希望它显示为:"准备时间:55分钟"

        public String Preparation
    {
        get { return "Preparation time: " + Preptime + " minutes"; }
    }
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用一个getter来做一个干净的解决方案,但必须有一种方法将它直接写入我的xaml?

提前致谢!

Sco*_*ain 7

StringFormat在绑定上使用该属性.

<TextBlock Text="{Binding Preptime, StringFormat=Preparation time: {0} minutes}"></TextBlock>
Run Code Online (Sandbox Code Playgroud)

它的行为与...相同 String.Format


Gle*_*enn 2

经过一些额外的搜索后,我发现使用运行可能是最简单的解决方案。更多信息请参见:Windows Phone 8.1 XAML StringFormat

                <TextBlock>
                <Run Text="Preparation time: "></Run>
                <Run Text="{Binding Preptime}"></Run>
                <Run Text=" minutes."></Run>
            </TextBlock>
Run Code Online (Sandbox Code Playgroud)