今回は前回のデータバインディングした値に、フォーマットを指定して表示するようにしてみます。
XAML
<Grid Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Style="{StaticResource baseGrid}"> <Label Text="{Binding stringValue, StringFormat='初期値は {0}'}" FontSize="Large"> </Label> </Grid> <Grid Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6" Style="{StaticResource baseGrid}"> <Label Text="{Binding intValue, StringFormat='intValue {0}'}" FontSize="Large"> </Label> </Grid> <Grid Grid.Column="5" Grid.ColumnSpan="2" Grid.Row="1" Style="{StaticResource baseGrid}"> <Label Text="{Binding dateValue, StringFormat='今日は {0:yyyy/MM/dd}'}" FontSize="Large"> </Label> </Grid> <Grid Grid.Column="5" Grid.ColumnSpan="2" Grid.Row="6" Style="{StaticResource baseGrid}"> <Label Text="{Binding decValue, StringFormat='decValue {0:#,0}'}" FontSize="Large"> </Label> </Grid>
Binding の中に StringFormat を追記します。
StringFormatの書式は以下のMSDNが参考になるかと思います。
他は前回のデータバインディングと同様です。
実行結果
こんな感じで表示されました。
例によって、Xamarin.Forms Previewer には出てこないので、実行しながら内容を確認することになりそう。