0

次の XAML で定義された DatePicker があります。

<DatePicker Grid.Row="3" Grid.Column="1" Margin="4" 
    Text="{Binding Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
    DisplayDateStart="01.01.1900" DisplayDateEnd="{Binding CurrentDate, Mode=OneTime}"/>

「02.03.1979」のような日付を選択すると、すべて問題ありません。しかし、「27.12.1979」を選択すると、DatePicker のフィールドに赤い境界線が表示されます。この日付の検証はありません。

一部の日付が赤いのはなぜですか?

誕生日は Datetime 型のプロパティです。Currendate は、実際の日付を返す DateTime 型のプロパティです。

4

3 に答える 3

0

xamlコードは問題ありません。複数のDatePickerに同じDateTime形式を使用する場合は、このコードスニペットをスタートアップウィンドウに追加します。パターンを編集できます。

Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd. MMM. yyyy";  
于 2013-03-18T20:45:55.493 に答える
0

Text の代わりに DisplayDate にバインドすることで問題を解決しました。コードは次のようになります。

<DatePicker Grid.Row="3" Grid.Column="1" Margin="4" 
DisplayDate="{Binding Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayDateStart="01.01.1900" DisplayDateEnd="{Binding CurrentDate, Mode=OneTime}"/>
于 2013-03-18T21:30:09.893 に答える
-1

日付値の順序にこだわらない場合は、これを試してください

<DatePicker Grid.Row="3" Grid.Column="1" Margin="4" 
    Text="{Binding Birthday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
    DisplayDateStart="01.01.1900" DisplayDateEnd="{Binding CurrentDate, Mode=OneTime}" Format="Custom" FormatString="MMM dd yyyy"/>
于 2013-03-18T20:46:24.733 に答える