我想要TimePicker的选定日期。当我从日历中选择特定日期时,该日期应该分配给Timepicker。
的Xaml:
<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;
}
}
想法?
答案 0 :(得分:3)
您绑定到不存在的属性。将绑定从StartValue和EndValue更改为StartTime和EndTime。
TimePicker:
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事件以查看是否清除它。 example with onPropertyChanged