Binding の StringFormat のスニペット
via http://blogs.msdn.com/llobo/archive/2008/05/19/wpf-3-5-sp1-feature-stringformat.aspx
.NET3.5 SP1から追加された Binding の StringFormat のスニペットが載ってます。こんな書き方ができたなんて知らなかった…。全部の書き方知ってた?このドキュメントは、そのまま MSDN に収録すべき!
ItemStringFormat, ContentStringFormat, HeaderStringFormat なんてものあるようで。
以下、ポイントだけ引用。
<TextBox Text="{Binding Path=Double, StringFormat=F3}"/> <TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/> <TextBox Text="{Binding Path=Double, StringFormat=Amount: \{0:C\}}"/> <TextBox> <TextBox.Text> <Binding Path="Double" StringFormat="{}{0:C}"/> </TextBox.Text> </TextBox>