[編輯]據對我來說,我更喜歡我以前的答案。所以請確保你,讀者,我以前的答案不符合你的期望。
另一個答案是把你的對象放在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