0

我想要为我的 TimePicker 选择日期。当我从显示在我的视图窗口中的日历中选择特定日期时,该日期应分配给 Timepicker。

xml:

<DataTemplate x:Key="EditableDataTemplate">
  <StackPanel Orientation="Horizontal" Width="596">
   <xctk:TimePicker Name="StartPicker" Value="{Binding StartTime, Mode=TwoWay}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="100" EndTime="11:59:0"/>
   <xctk:TimePicker Name="EndPicker" Value="{Binding EndTime, Mode=TwoWay}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="60" EndTime="11:59:0"/>
  </StackPanel>
</DataTemplate>

下面的属性更新 TimePicker 的时间,但设置今天的日期。我想要在运行时选择的选定日期。

private DateTime _started_at;
private DateTime _ended_at;

public DateTime StartTime
    {
        get
        {
            return _started_at;
        }
        set
        {
            _started_at = value;
        }
    }

    public DateTime EndTime
    {
        get
        {
            return _ended_at;
        }
        set
        {
            _ended_at = value;
        }
    } 

想法?

4

1 回答 1

3

您正在绑定到不存在的属性。将您的绑定从 StartValue 和 EndValue 更改为 StartTime 和 EndTime。

时间选择器:

public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; } 

XAML:

<DataTemplate x:Key="EditableDataTemplate">
  <StackPanel Orientation="Horizontal" Width="596">
   <xctk:TimePicker Name="StartPicker" Value="{Binding StartTime, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="100" EndTime="11:59:0"/>
   <xctk:TimePicker Name="EndPicker" Value="{Binding EndTime, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="60" EndTime="11:59:0"/>
  </StackPanel>
</DataTemplate>

编辑做了一些 google-jerking 并意识到您没有任何关于财产更改的通知。尝试添加 INotifyPropertyChanged 接口,并引发 OnPropertyChanged 事件以查看是否可以清除它。onPropertyChanged 示例

于 2013-08-14T14:19:34.037 回答