Binding の StringFormat プロパティのカルチャって ?
String.Format () でカルチャに依存する書式を指定した場合、カルチャを指定しないとそのスレッドのカルチャ情報が使用されるらしいです。具体的には System.Threading.Thread.CurrentThread.CurrentCulture です。
が、BindingBase の StringFormat で指定した場合、カレントスレッドのカルチャ情報と異なるように見えますがー。なんか私間違ってますかー ? 何か指定がいるのー ?
<Window x:Class="SampleApp.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:th="clr-namespace:System.Threading;assembly=mscorlib" Title="Binding の StringFormat のカルチャって?" SizeToContent="WidthAndHeight"> <StackPanel Grid.IsSharedSizeScope="True"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Caption"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Margin="5" Text="StringFormat なし"/> <TextBlock Grid.Column="1" Margin="5" Text="{Binding Source={x:Static sys:DateTime.Now}}"/> </Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Caption"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Margin="5" Text="StringFormat あり"/> <TextBlock Grid.Column="1" Margin="5" Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat={}{0:F}}"/> </Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Caption"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Margin="5" Text="CurrentUICulture の設定"/> <TextBlock Grid.Column="1" Margin="5" Text="{Binding Source={x:Static th:Thread.CurrentThread}, Path=CurrentUICulture.DateTimeFormat.FullDateTimePattern}"/> </Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" SharedSizeGroup="Caption"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Margin="5" Text="CurrentCulture の設定"/> <TextBlock Grid.Column="1" Margin="5" Text="{Binding Source={x:Static th:Thread.CurrentThread}, Path=CurrentCulture.DateTimeFormat.FullDateTimePattern}"/> </Grid> <Button Margin="5" Click="Button_Click">String.Format の結果</Button> </StackPanel> </Window>
namespace SampleApp { /// <summary> /// Window1.xaml の相互作用ロジック /// </summary> public partial class Window1 : Window { public Window1 () { InitializeComponent (); } private void Button_Click (object sender, RoutedEventArgs e) { MessageBox.Show (String.Format ("{0:F}", System.DateTime.Now)); } } }
トラックバック
- このエントリーにトラックバック:
- http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/2304
コメント