[编辑]据对我来说,我更喜欢我以前的答案。所以请确保你,读者,我以前的答案不符合你的期望。
另一个答案是把你的对象放在ComboBox上面,然后从这个对象上捕获MouseDown事件并且放下ComboBox。在我的例子中,我使用了只读文本框。
参见:
<Grid>
<ComboBox x:Name="Combo" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="120">
<ComboBoxItem Content="TEST" />
<ComboBoxItem Content="TEST1" />
<ComboBoxItem Content="TEST2" />
<ComboBoxItem Content="TEST3" />
</ComboBox>
<TextBox HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" Text="TextBox" VerticalAlignment="Top" Width="120" IsReadOnly="True" PreviewMouseDown="TextBox_PreviewMouseDown"/>
</Grid>
然后后面的代码:
private void TextBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true; // Prevents the event.
Combo.IsDropDownOpen = true; // Drops down the ComboBox.
}
它工作正常的我。
它不是很好吗?您是否尝试使用ComboBox上方的只读编辑框?结果看起来完全像你的例子。太糟糕了,不符合你的期望。我很高兴你的上下文菜单包围了! – Marc
我发现组合不适合我的整体外观,但感谢您的帮助,因为我将更有可能使用我在这里学到的东西。 – DIGGIDY