如何使用属性更改 TimePicker 格式 [英] How to change TimePicker format using properties
问题描述
我使用扩展的 wpf 工具包在我的 wpf 应用程序中使用了 TimePicker 格式.我正在使用HH:MM"格式.但问题是,允许直接从选项中选择小时的按钮,显示 24 小时格式,但我只想要 12 小时.但是我通过将 Endtime 从23:59"更改为11:59",通过 TimePicker 的属性实现了这一点.但是那些上下按钮仍然显示小时到23.所以,如果我想达到11,我该怎么办?我可以仅通过 TimePicker 的属性来实现吗?它也没有显示一天的一部分,即上午/下午.我还想要另一个按钮,它应该向我显示这两个选项(即 AM 和 PM).请提出建议,我应该如何进行?
I've used TimePicker format in my wpf application using extended wpf toolkit. I'm using "HH:MM" format. but problem is, the button which allows to select hours directly from the options, showing 24 hours format, but I want 12 hours only. But I managed that through properties of TimePicker by changing Endtime from "23:59" to "11:59". But those up and down buttons still showing hours upto 23. so, If I want to make upto 11, what should I do? Can I achieve this by TimePicker's property only? also It's not showing part of day i.e AM/PM. I also want another button which should show me these two options (i.e AM and PM). Please suggest, how should I proceed?
我后面的代码中绑定到DateTime对象的Timepicker控件如下,
My Timepicker controls which are bound to DateTime object in my code behind are as follows,
<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>
我的窗口的用户界面-
推荐答案
使用 FormatString
属性来格式化您的显示.我认为您已经在之前的问题中涵盖了格式.您还应该将 Format
设置为 Custom
.
Use the FormatString
property to format your display. I think you have the formats covered in your previous questions. You should also set Format
to Custom
.
这里有一个建议:
<xctk:TimePicker Format="Custom" FormatString="hh:mm:ss tt" />
您应该注意,使用 HH
表示小时为您提供 24 小时格式,而 hh
将为您提供 12 小时格式.
You should note that using HH
for hours gives you 24-hour format, while hh
will give you a 12-hour format.
您可以在此处查看文档.
这篇关于如何使用属性更改 TimePicker 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!