我有一个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>
答案 0 :(得分:0)
我会尝试mode = twoway并确保在该属性上有一个get set并取消该事件。我知道你想要这个活动,但如果事件是破坏它,那么至少你知道事件正在破坏它。您可以跟踪并查看是否已设置为已触发。我和其他评论一起 - 你为什么要这样做?