How to change TimePicker format using properties

若如初见. 提交于 2019-12-24 03:14:38

问题


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?

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>

UI of my Window-


回答1:


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.

Here's a suggestion:

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

You should note that using HH for hours gives you 24-hour format, while hh will give you a 12-hour format.

You can check the documentations here.



来源:https://stackoverflow.com/questions/17739768/how-to-change-timepicker-format-using-properties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!