ViewMakerで生成するWPF/Silverlightコントロール(8)DatePicker編

今回はDatePickerです。

DatePickerコントロール

WPFは標準ですが、SilverlightSDKが必要です。DateTime型またはString型をSelectedDateにバインドして利用します。
ViewMakerで指定可能なDatePickerの項目は以下の通りです。

    1. SelectedDateFormat(選択した日時のフォーマット)

WPFサンプルイメージとXAMLコード

<DatePicker Name="DatePicker1" SelectedDate="{Binding Path=DatePicker1, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" />

<DatePicker Name="DatePicker2" SelectedDate="{Binding Path=DatePicker2, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" SelectedDateFormat="Long" />

<DatePicker Name="DatePicker3" SelectedDate="{Binding Path=DatePicker3, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" SelectedDateFormat="Short" Width="200" Foreground="Blue" Background="Azure" 
	HorizontalAlignment="Left">
    <DatePicker.Resources>
        <Style TargetType="{x:Type DatePickerTextBox}">
           <Setter Property="Foreground" Value="Blue" />
           <Setter Property="Background" Value="Azure" />
        </Style>
    </DatePicker.Resources>
</DatePicker>

SilverlightサンプルイメージとXAMLコード

<sdk:DatePicker Name="DatePicker1" SelectedDate="{Binding Path=DatePicker1, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" /> 

<sdk:DatePicker Name="DatePicker2" SelectedDate="{Binding Path=DatePicker2, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" SelectedDateFormat="Long" />

<sdk:DatePicker Name="DatePicker3" SelectedDate="{Binding Path=DatePicker3, Mode=TwoWay, ValidatesOnExceptions=True, 
	ValidatesOnDataErrors=True}" SelectedDateFormat="Short" Width="200" Foreground="Blue" Background="Azure" 
	HorizontalAlignment="Left" />

ViewModelコード

[View(ViewControlType.StackPanel)]
[ViewProperty(StackPanelViewControl.Properties.HeaderPosition, LayoutHeaderPosition.Hidden)]
public class DatePickerSample : ViewModel
{
    [View(ViewControlType.DatePicker)]
    public string DatePicker1 { get; set; }

    [View(ViewControlType.DatePicker)]
    [ViewProperty(DatePickerViewControl.Properties.SelectedDateFormat, "Long")]
    public DateTime DatePicker2 { get; set; }

    [View(ViewControlType.DatePicker)]
    [ViewProperty(DatePickerViewControl.Properties.Width, 200)]
    [ViewProperty(DatePickerViewControl.Properties.Foreground, "Blue")]
    [ViewProperty(DatePickerViewControl.Properties.Background, "Azure")]
    [ViewProperty(DatePickerViewControl.Properties.SelectedDateFormat, "Short")]
    public DateTime? DatePicker3 { get; set; }

    public DatePickerSample()
    {
        DatePicker1 = "2000/1/1";
        DatePicker2 = DateTime.Now;
    }
}