如何在时间选择器中设置最小和最大时间(wp8.1)

时间:2022-09-26 21:07:58

Is some way to narrow displayed hours in TimePicker? I didn't find any appropriate properties (hard to believe,there is no such a possibility),also tried using data context:

是否有办法缩短在时间选择器中显示的时间?我没有找到任何合适的属性(难以置信,没有这种可能性),也尝试使用数据上下文:

class TimePickerDataSource
{

    public List<TimeSpan> Hours { get; set; }

    public TimePickerDataSource()
    {
        Hours = new List<TimeSpan>{new TimeSpan(9,0,0),new TimeSpan(10,0,0)};
    }
}

and later in MyPage.xaml.cs:

后来在MyPage.xaml.cs:

      StartTimePicker.DataContext = new TimePickerDataSource();

but i don't know how to bind it in my xaml (if it is possible):

但是我不知道如何在我的xaml中绑定它(如果可能的话):

<Grid x:Name="My Grid">
    <TextBlock  HorizontalAlignment="Left" Margin="129,129,0,0" TextWrapping="Wrap" Text="{Binding DisplayedName}" VerticalAlignment="Top" Height="60" Width="163" FontSize="20" />
    <TimePicker x:Name="StartTimePicker" HorizontalAlignment="Left" Margin="168,259,0,0" VerticalAlignment="Top" ClockIdentifier="24HourClock">
    </TimePicker>


</Grid>

1 个解决方案

#1


0  

In C# code you could try this.

在c#代码中,您可以尝试这样做。

        this.dateTimePicker1.MaxDate = new System.DateTime(2015, 12, 31, 0, 0, 0, 0);
        this.dateTimePicker1.MinDate = new System.DateTime(1999, 1, 1, 0, 0, 0, 0);

#1


0  

In C# code you could try this.

在c#代码中,您可以尝试这样做。

        this.dateTimePicker1.MaxDate = new System.DateTime(2015, 12, 31, 0, 0, 0, 0);
        this.dateTimePicker1.MinDate = new System.DateTime(1999, 1, 1, 0, 0, 0, 0);