6

私のwpfアプリケーションのCustomViewウィンドウで、宣言したプロパティは次のとおりです。

private DateTime starttime 
    {
        get
        {
            return DateTime.Parse(StartTimeText.Text); 
        }
        set
        {
            StartTimeText.Text = value.ToString();
            OnPropertyChanged("starttime");
        } 
    }

    private DateTime stoptime
    {
        get
        {
            return DateTime.Parse(StopTimeText.Text);
        }
        set
        {
            StopTimeText.Text = value.ToString();
            OnPropertyChanged("stoptime");
        }
    }

protected virtual void OnPropertyChanged(String time)
    {
        if (System.String.IsNullOrEmpty(time))
        {
            return;
        }
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(time));
        }
    }

public event PropertyChangedEventHandler PropertyChanged;

xamlでは、

<DatePicker x:Name="StartTimeText" 
            SelectedDate="{Binding Path=starttime}"  
            BorderThickness="0" 
            Background="Yellow"
            Width="100"/>

<DatePicker x:Name="StopTimeText" 
            SelectedDate="{Binding Path=stoptime, Mode=TwoWay}" 
            BorderThickness="0" 
            Background="Yellow"
            Width="60"/>

このようにして、starttime コントロールと stoptime コントロールで Date を取得しています。しかし、「hh:mm tt」形式の時間が必要です。DateTimePicker コントロールは、WPF ツールボックスでは使用できません。日付の代わりに指定された形式で時間を取得するには、どうすればよいですか? 提案してください。

4

1 に答える 1

10

http://wpftoolkit.codeplex.com/documentationを使用してみてください

次の名前空間を参照してください

xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" 

その後

<xctk:DateTimePicker x:Name="dtpStartTime"  
                     Format="Custom" 
                     FormatString="HH:mm tt" 
                     Margin="5"/>
于 2013-07-12T07:35:13.983 に答える