简体   繁体   English

WPF 组合框 + MouseLeftButtonDown

[英]WPF Combo box + MouseLeftButtonDown

Hopefully someone can help because I haven't been able to figure this out.希望有人可以提供帮助,因为我无法弄清楚这一点。 Here's my xaml code for the popup/combo box, please not there is other code before and after this for the rest of the layout.这是弹出/组合框的 xaml 代码,请不要在此之前和之后为布局的 rest 有其他代码。

    <Popup x:Name="popupMethods" Height="400" Width="150" 
       StaysOpen="False" Placement="Bottom" IsOpen="false"
       HorizontalAlignment="Left">
                <ComboBox x:Name="combo" MouseLeftButtonDown="combo_MouseDown">
                    <TextBlock>Hello</TextBlock>
                    <TextBlock>World</TextBlock>
                    <TextBlock>This</TextBlock>
                    <TextBlock>is</TextBlock>
                    <TextBlock>Autocomplete</TextBlock>
                    <TextBlock>Textbox</TextBlock>
                </ComboBox>
    </Popup>

Have it set up to popup on the screen whenever the user starts typing, which works.将其设置为在用户开始输入时在屏幕上弹出,这很有效。 The problem is I want the user to be able to click one of the words in the combo box and that gets inserted into the text box.问题是我希望用户能够单击组合框中的一个单词并将其插入到文本框中。 This parts not working as the MouseLeftButtonDown is never being fired.这部分不起作用,因为 MouseLeftButtonDown 永远不会被解雇。 I've tried a couple of different methods including the one from this site http://www.designerwpf.com/2008/12/03/getting-a-mouseleftbuttondown-or-mouseleftbuttonup- event-from-your-textbox/我尝试了几种不同的方法,包括来自此站点的一种方法http://www.designerwpf.com/2008/12/03/getting-a-mouseleftbuttondown-or-mouseleftbuttonup-event-from-your-textbox/

as well as one I saw somewhere else that was combo.MouseLeftButtonDown += delegate { };以及我在其他地方看到的一个是 combo.MouseLeftButtonDown += delegate { };

Thanks for any help.谢谢你的帮助。

Instead of MouseLeftButtonDown event handler, use PreviewMouseLeftButtonDown you can achieve the same.代替MouseLeftButtonDown事件处理程序,使用PreviewMouseLeftButtonDown可以实现相同的目的。

You probably want to look at the SelectionChanged event.您可能想查看SelectionChanged事件。 It fires whenever an item in the ComboBox's drop down is selected. It fires whenever an item in the ComboBox's drop down is selected.

I think that the ComboBox internally handles the MouseLeftButtonDown event, and that is causing it not to be passed on to your code.我认为 ComboBox 在内部处理MouseLeftButtonDown事件,这导致它不会传递给您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM