vishwas 115
vishwas 115

Reputation: 23

WPF TimePicker Control get only time

I am using TimePicker control for the first time. I want to get the selected time into my ViewModel as well as bind the selected time into a textblock/textbox. I am able to bind the TextBox to selected to selected value But it displays Date As well with time. I want to display only time meaning, get only time from TimePicker.

The textbox data looks like- 2/8/2015 10:18:35 PM What I want to display is - 10:18:35 PM

<Window Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <vm:Data></vm:Data>
    </Window.DataContext>
    <Grid>
        <TimePick:TimePicker Name="tp" Format="LongTime" 
                             FormatString="hh:mmtt"
                             Margin="10,52,174,244"/>
        <TextBox Text="{Binding Path=Value, ElementName=tp}"
                Margin="0,127,174,153"></TextBox>
    </Grid>
</Window>

Upvotes: 1

Views: 6569

Answers (1)

SamTh3D3v
SamTh3D3v

Reputation: 9944

add StringFormat

<Grid>
    <TimePick:TimePicker Name="tp" Format="LongTime"  FormatString="hh:mmtt"       Margin="10,52,174,244"/>
    <TextBox Text="{Binding Path=Value, StringFormat='HH:mm:ss' , ElementName=tp}"  Margin="0,127,174,153"></TextBox>
  </Grid>

Upvotes: 2

Related Questions