如何从C#中的TimePicker(WPF)获取价值?

时间:2019-03-21 18:42:59

标签: c# wpf

我从visualstudio的nuget下载了MaterialDesignTheme。 http://materialdesigninxaml.net/

如何从TimePicker获得价值? 我想将此值存储在字符串缓冲区中。 如何实现MainWindow.xaml.cs?

<Grid Grid.Row="1" Grid.Column="1">
            <materialDesign:TimePicker
              Is24Hours="True"
              x:Name="PresetTimePicker"
              SelectedTimeChanged="PresetTimePicker_SelectedTimeChanged" Height="26" Margin="141,94,369,0" RenderTransformOrigin="-0.025,5.923" />
        </Grid>

1 个答案:

答案 0 :(得分:1)

TimePicker控件具有一个SelectedTime属性,该属性返回一个DateTime?

DateTime selectedTime = PresetTimePicker.SelectedTime.Value;
string formatted = selectedTime.ToString("HH:mm:ss");