C# GroupBox标头绑定中的StringFormat不';好像不行
我正在尝试将C# GroupBox标头绑定中的StringFormat不';好像不行,c#,xaml,bind,string-formatting,ivalueconverter,C#,Xaml,Bind,String Formatting,Ivalueconverter,我正在尝试将GroupBox的标题文本绑定到属性,并使用StringFormat显示它 第一部分工作正常,并按预期返回文本。但是我想把最后的文本格式化。例如,当我返回cm时,我希望它显示为基础高度(cm),但下面的代码仅显示cm <GroupBox Header="{Binding CurrentTargetUnit, Converter={StaticResource QuantityToTextConverter}, ConverterParameter={x:Sta
GroupBox
的标题文本绑定到属性,并使用StringFormat
显示它
第一部分工作正常,并按预期返回文本。但是我想把最后的文本格式化。例如,当我返回cm
时,我希望它显示为基础高度(cm)
,但下面的代码仅显示cm
<GroupBox Header="{Binding CurrentTargetUnit,
Converter={StaticResource QuantityToTextConverter},
ConverterParameter={x:Static enumerations:Quantity.Length},
StringFormat='Foundation Height ({0})'}">
</GroupBox>
尝试不加引号
....
StringFormat=Foundation Height ({0})}">
更新
由于您已经对标头使用了绑定,因此应该改用HeaderStringFormat
....
HeaderStringFormat=Foundation Height ({0})}">
阅读更多信息,请尝试以下方法:
StringFormat={}Foundation Height ({0})}">
我也有同样的问题。我找到了答案
您还需要从StringFormat中删除引号。此外,在上面的链接中,它显示了将“{}”放在StringFormat中的任何内容之前。如果我没记错的话,您只需要在占位符是first:StringFormat={}{0:C}时使用它
允许StringFormat绑定的元素数量有限,TextBlock是一个,GroupBox头不允许。@FirstStep仍然是一样的。这很奇怪!对于
GroupBox
,StringFormat
似乎不起作用。我用HeaderStringFormat
试过了,现在可以用了。给这个人一块饼干!另外,{}
只有在StringFormat
以占位符开头时才是必需的(如{0}
)。
<GroupBox>
<GroupBox.Header>
<TextBlock Text="{Binding CurrentTargetUnit,
Converter={StaticResource QuantityToTextConverter},
ConverterParameter={x:Static enumerations:Quantity.Length},
StringFormat=Foundation Height ({0})}">
</GroupBox.Header>
</GroupBox>