2013-07-19 23 views
1

我在使用扩展wpf工具包的wpf应用程序中使用了TimePicker格式。我正在使用“HH:MM”格式。但问题是,该按钮允许直接从选项中选择小时,显示24小时格式,但我只需要12小时。但是,通过将Endtime从“23:59”更改为“11:59”,我通过TimePicker的属性来管理该属性。但那些上下按钮仍然显示小时数达到23.所以,如果我想弥补11,我该怎么办?我可以通过TimePicker的属性来实现吗?也没有显示部分时间,例如上午/下午。我还想要另一个按钮,它应该显示我这两个选项(即AM和PM)。请建议,我应该如何继续?如何使用属性更改TimePicker格式

这必将对DateTime对象在我的代码我Timepicker控件后面有:

<Window x:Class="TimeSheet.CustomView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" 
    x:Name="Time" 
    Title="CustomView" Width="596" Height="596"> 
<Grid> 
    <StackPanel Orientation="Horizontal" Height="30" Width="596" Margin="0,137,-8,399"> 
     <xctk:TimePicker x:Name="StartTimeText" Value="{Binding starttime, ElementName=Time, Mode=TwoWay}" BorderThickness="0" Background="Yellow" Width="113" EndTime="11:59:0" AllowSpin="False"/> 
     <xctk:TimePicker x:Name="StopTimeText" Value="{Binding stoptime, ElementName=Time, Mode=TwoWay}" BorderThickness="0" Background="Yellow" Width="115" EndTime="11:59:0" AllowSpin="False"/> 
    </StackPanel>    
</Grid> 
</Window> 

我的窗口 -

enter image description here

回答

2

使用的UI的FormatString属性来格式化显示。我认为你有以前的问题涵盖的格式。您还应该将Format设置为Custom

这里有一个建议:

<xctk:TimePicker Format="Custom" FormatString="hh:mm:ss tt" /> 

你应该注意到,使用HH几个小时为您提供24小时的格式,而hh会给你一个12小时格式。

您可以检查文档here

+0

但是,此控件没有TimeFormatString属性。它是FormatString属性。我有FormatString属性,但它不显示部分时间(即AM/PM)。 – Dinesh

+0

对不起,我把它与'DateTimePicker'混合在一起。我编辑了答案 – Vanlalhriata

+0

现在,它只显示AM的一部分。这意味着从凌晨1:00到凌晨12:00显示 – Dinesh