我有一个wpf combobox ...这是不可用的。当我打入此组合时...我有一个样式的设置器(<Setter Property="IsDropDownOpen" Value="True"/>
)打开ComboBox。但是,当我再次标记时。焦点移至打开的combobox中的下一个项目....然后在那儿循环。我无法表现到下一个控件。
这里有什么问题?
谢谢
尝试:
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsTabStop" Value="False"/>
</Style>
或
使用键盘名录:
WPF标签订单带有自定义控件?
不推荐,而是有效...
<Grid>
<ComboBox Grid.Row="1" Margin="0,0,0,0" Name="comboBox1" HorizontalAlignment="Left" Width="120" Height="20" IsEditable="False" KeyDown="comboBox1_KeyDown" GotKeyboardFocus="comboBox1_GotKeyboardFocus" >
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsDropDownOpen" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBoxItem>Male</ComboBoxItem>
<ComboBoxItem>Female</ComboBoxItem>
<ComboBoxItem>Unknown</ComboBoxItem>
</ComboBox>
</Grid>
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
ComboBox cb = sender as ComboBox;
if (e.Key == Key.Tab && cb.IsDropDownOpen)
{
ComboBoxItem item = FocusManager.GetFocusedElement(Window.GetWindow(this)) as ComboBoxItem;
cb.SelectedItem = item;
cb.IsDropDownOpen = false;
e.Handled = true;
}
}
private void comboBox1_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
ComboBox cb = sender as ComboBox;
cb.IsDropDownOpen = true;
}
您可以通过以下代码实现相同的操作: -
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
IsDropDownOpen = true;
e.Handled = true;
}
}
现在,当焦点将设置在combobox上时,您需要点击Enter即可打开下拉下拉,您可以使用关键字来浏览Combobox项目。要移至下一个控件,您需要按下选项卡。
我有相同的问题,在xaml中这样解决了:
<Style x:Key="RadComboBoxItemStyle" TargetType="telerik:RadComboBoxItem">
<Setter Property="Focusable"
Value="False" />
<Setter Property="IsHitTestVisible"
Value="True" />