WinUI-Gallery icon indicating copy to clipboard operation
WinUI-Gallery copied to clipboard

Suggestion: show how to initialize TimePicker to the current time

Open StigAlgardstad opened this issue 5 years ago • 4 comments

Is this a totally new sample, an addition to an existing sample page, or a modification of an existing sample page?

  • [ ] New sample
  • [x] Addition to existing sample
  • [ ] Modification to existing sample

If this is an addition/modification to an existing sample page, which one? TimePicker

Describe the sample

Show an example of how to initialize the TimePicker to the current time i XAML

Is your sample request related to a problem? Please describe it

Additional context

StigAlgardstad avatar Aug 07 '20 22:08 StigAlgardstad

I don't think there is a way to do this purely in XAML as there isn't a "pure XAML" way to get the current time. Would you be interested in a way how to set this through a binding to a property from code behind?

marcelwgn avatar Sep 05 '20 13:09 marcelwgn

CC: @kikisaints - any ideas?

stmoy avatar Oct 19 '20 20:10 stmoy

Got this, so far.

<Page
    x:Class="App2.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="using:System"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <TimePicker x:Name="myTimePicker" ClockIdentifier="24HourClock" Header="24 hour clock" SelectedTime="{x:Bind sys:DateTime.Now.TimeOfDay}"/>
    </StackPanel>
</Page>

StigAlgardstad avatar Oct 19 '20 23:10 StigAlgardstad

@stigAlgardstad That's awesome, would you be able to submit a PR with this sample?

karkarl avatar Feb 22 '24 19:02 karkarl