开发者

WPF - Lost ability to input date via keyboard?

开发者 https://www.devze.com 2023-03-29 06:57 出处:网络
I have a WPF user control that makes use of a ComboBox to contain a DatePicker.Unfortunately, when I put the DatePicker into the ComboBox, I seem to lose the ability to enter the date through the keyb

I have a WPF user control that makes use of a ComboBox to contain a DatePicker. Unfortunately, when I put the DatePicker into the ComboBox, I seem to lose the ability to enter the date through the keyboard; only the Calendar and mouse work.

Any ideas?

Also, here's my XAML:

<ComboBox Name="cboCombo" IsReadOnly="True" IsEditable="True" Foreground="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=Foreground}" DropDownOpened="cboCombo_DropDownOpened" DropDownClosed="cboCombo_DropDownClosed">
            <ComboBox.Text>
                <MultiBinding Converter="{StaticResource DateTimeTextConverter}" Mode="OneWay">
                    <Binding RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type UserControl}}" Path="SelectedDateAndTime" Mode="OneWay" />
                    <Binding RelativeSource="{RelativeSource FindAncestor,AncestorType={x:Type UserControl}}" Path="ShowTime" />
                </MultiBinding>
            </ComboBox.Text>
            <ComboBoxItem IsSelected="True">
                <ComboBoxItem.Template>
                    <ControlTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <DatePicker Grid.Row="0" Grid.Column="0" SelectedDate="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=SelectedDateAndTime}" SelectedDateChanged="BCDatePicker_SelectedDateChanged" />
                            <controls:TimePicker Grid.Row="0" Grid.Column="1" MouseUp="TimePicker_MouseUp" Loaded="TimePicker_Loaded" Time="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=SelectedDateAndTime,Mode=OneWay}" Visibility="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=ShowTime, Converter={StaticResource VisibilityConverter}}" />

                            <Button Grid.Row="1" Grid.Column="0" Content="Today" Click="Button_Click" />
                            <Button Grid.Row="1" Grid.Column="1" Content="Clear" Click="Button_Click_1" />

                  开发者_高级运维          <Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="View Date Calculator" Click="Button_Click_2" Visibility="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=ShowDateCalculator,Mode=OneWay,Converter={StaticResource VisibilityConverter}}" />

                            <Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=SelectedDateAndTime,Mode=OneWay,Converter={StaticResource HolidayDateConverter}}" Foreground="Red" />
                        </Grid>
                    </ControlTemplate>
                </ComboBoxItem.Template>
            </ComboBoxItem>
        </ComboBox>


I would try mode=twoway and make sure there is a get set on the property and take off the event. I understand you want the event but if the event is is breaking it then at least you know the event is breaking it. And you can trace and see if set if fired. I am with the other comments - why do you want to do this?

0

精彩评论

暂无评论...
验证码 换一张
取 消