WPF Toolkit DateTimePicker makes Time textbox irreplaceable

I am trying to make a calendar time picker to have a read-only textbox. As it defaults to allowing the user to enter an invalid time and throws an out of range index. I like to just do the timing with the down arrows and disable text input in that text box.

I've tried using TimePickerVisibility

before hidden

, but it hides the timing.

enter image description here

+3


source to share


1 answer


UPDATE 1
I just noticed that you are using a DateTimePicker and not a TimePicker,
so you need to set the TimePicker on the DateTimePicker so that it does not allow TextInput like this:

    <xctk:DateTimePicker HorizontalAlignment="Left" Margin="67,200,0,0" VerticalAlignment="Top" Width="228">
        <xctk:DateTimePicker.Resources>
            <Style TargetType="{x:Type xctk:TimePicker}">
                <Setter Property="AllowTextInput" Value="False"/>
            </Style>
        </xctk:DateTimePicker.Resources>
    </xctk:DateTimePicker>

      

UPDATE2
If you want to disable all TextInputs so that the user cannot enter any date or time, you can do it like this:



<xctk:DateTimePicker HorizontalAlignment="Left" Margin="67,200,0,0" VerticalAlignment="Top" Width="228">
    <xctk:DateTimePicker.Resources>
        <Style TargetType="{x:Type xctk:DateTimePicker}">
            <Setter Property="AllowTextInput" Value="False"/>
        </Style>
        <Style TargetType="{x:Type xctk:TimePicker}">
            <Setter Property="AllowTextInput" Value="False"/>
        </Style>
    </xctk:DateTimePicker.Resources>
</xctk:DateTimePicker>

      

If you use a standard DatePicker, it will be done as follows. For a standard WPF DatePicker, you need to set the DatePickerTextBox to ReadOnly. You can do it like this:

<DatePicker HorizontalAlignment="Left" Margin="138,82,0,0" VerticalAlignment="Top">
    <DatePicker.Resources>
        <Style TargetType="DatePickerTextBox">
            <Setter Property="IsReadOnly" Value="True"/>
        </Style>
    </DatePicker.Resources>
</DatePicker>

      

+2


source







All Articles