私はしばらくの間WPF
で遊んでいました。面白いことが出てきました。 DateTime
オブジェクトをLabel
のコンテンツにバインドすると、ローカルに書式設定された日付が表示されます。しかし、TextBlock
のTextプロパティにバインドすると、実際に英語が表示されます。LabelとTextBlockの文化の違い
TextBlock
は何らかのコンバータを使用していますが、Label
はちょうどToString
メソッドを呼び出しているようですが、わかりません。
もしそうなら、なぜLabel
もコンバータを使用していませんか?
誰かが私に説明することができますそれはそれが動作している理由は何ですか?私はあなたに何が起こっているのかを見てもらうための短いサンプルを提供します:
// MainWindow.xaml
<Window x:Class="BindConversion.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel HorizontalAlignment="Center" Margin="3">
<StackPanel>
<Label Content="{Binding Dt}"/>
<TextBlock Text="{Binding Dt}"/>
</StackPanel>
</StackPanel>
</Window>
// MainWindow.xaml.cs
using System;
using System.Windows;
namespace BindConversion
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public DateTime Dt { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
Dt = DateTime.Now;
}
}
}
... String型のプロパティに何かをバインドするだけで 'ToString() 'が呼び出されます。 –
Right、TextBoxはContentPresenterから派生していないため、コンバーターを使用していません。それは今私には意味がある。ありがとうございました。 – greenshade
歓迎!!! – Aybe