У меня есть пользовательский элемент управления WPF, который использует ComboBox для хранения DatePicker. К сожалению, когда я помещаю DatePicker в ComboBox, я, кажется, теряю возможность вводить дату с клавиатуры; работают только календарь и мышь.
Есть идеи?
Кроме того, вот мой 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>