I'm trying to bind the header text of aGroupBox
to a property and display it using StringFormat
.
The first part works and it returns the text as expected. But I want the final text to be formatted. For example when I return cm
I want it to be displayed as Foundation Height (cm)
, but the code below only shows cm
.
<GroupBox Header="{Binding CurrentTargetUnit,
Converter={StaticResource QuantityToTextConverter},
ConverterParameter={x:Static enumerations:Quantity.Length},
StringFormat='Foundation Height ({0})'}">
</GroupBox>
答案 0 :(得分:3)
Try without quotes
....
StringFormat=Foundation Height ({0})}">
UPDATE
As you have used binding for header you should use HeaderStringFormat
instead.
....
HeaderStringFormat=Foundation Height ({0})}">
Read the documentation for more
答案 1 :(得分:0)
Try this instead:
StringFormat={}Foundation Height ({0})}">
答案 2 :(得分:0)
我有同样的问题。我找到了答案here。
If ibasic Like "A1*" Or ibasic Like "A2*" Or ibasic Like "A3*" Or ibasic Like "A4*" Or ibasic Like "A5*" Or ibasic Like "A6*" Or ibasic Like "A7*" Or ibasic Like "A8*" Or ibasic Like "B1*" Or ibasic Like "B2*" Or ibasic Like "B3*" Or ibasic Like "B4*" Or ibasic Like "B5*" Or ibasic Like "B6*" Or ibasic Like "B7*" Or ibasic Like "B8*" Or ibasic Like "F1*" Or ibasic Like "F2*" Or ibasic Like "F3*" Or ibasic Like "F4*" Or ibasic Like "F5*" Or ibasic Like "F6*" Or ibasic Like "F7*" Or ibasic Like "F8*" Or ibasic Like "C1*" Or ibasic Like "S1*" Then
您还需要从StringFormat中删除引号。另外,在上面的链接中,它显示了在StringFormat中的任何内容之前放置“ {}”。如果我没记错的话,只需要占位符在第一位即可:StringFormat = {} {0:C}
允许StringFormat绑定的元素数量有限,TextBlock为一个,而GroupBox标头则不允许。