Search code examples
c#wpfmahapps.metro

DateTimePicker: how can I remove the "time" section?


I've a generic DateTimePicker control in MahApps:

<controls:DateTimePicker x:Name="CreationDate"
                         SelectedDateTime="{Binding CreationDate}"
                         Width="170"
                         Height="40"
                         HorizontalAlignment="Left"
                         VerticalAlignment="Top"
                         Culture="en-US"
                         Focusable="False"
                         controls:TextBoxHelper.Watermark="Creation Date"
                         controls:TextBoxHelper.UseFloatingWatermark="True"
                         SelectedDateFormat="Short"
                         SelectedTimeFormat="Short" />

But I'm not able to hide the Time (both on textbox, and on the popup opened when I click the icon.

How can I remove it?


Solution

  • I think I need to add some screenshots to show why I said you should just use the DatePicker of WPF.

    Here's what I got, a window with a DatePicker, a TimePicker and a DateTimePicker:

    MainWindow

    You can see that the styles of DatePicker and DateTimePicker are consistent, and you can customize the watermark.

    Here's the style after you click the icon:

    DatePicker DateTimePicker

    And the code:

    <mah:MetroWindow x:Class="WpfApp2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
            Title="MainWindow" Height="137" Width="212">
        <Grid>
            <mah:DateTimePicker HorizontalAlignment="Left"
                                VerticalAlignment="Top"
                                Margin="10,10,0,0" Width="140"
                                mah:TextBoxHelper.Watermark="Pick" />
            <DatePicker HorizontalAlignment="Left"
                        VerticalAlignment="Top"
                        Margin="10,41,0,0" Width="140"
                        mah:TextBoxHelper.Watermark="Pick" />
            <mah:TimePicker HorizontalAlignment="Left"
                            VerticalAlignment="Top"
                            Margin="10,72,0,0" Width="140"
                            mah:TextBoxHelper.Watermark="Pick" />
        </Grid>
    </mah:MetroWindow>