【问题标题】:WPF Combo box + MouseLeftButtonDownWPF 组合框 + MouseLeftButtonDown
【发布时间】:2015-12-31 11:24:58
【问题描述】:

希望有人可以提供帮助,因为我无法弄清楚这一点。这是我的弹出框/组合框的 xaml 代码,请不要在此之前和之后有其他代码用于其余布局。

    <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>

将其设置为在用户开始输入时在屏幕上弹出,这很有效。问题是我希望用户能够单击组合框中的一个单词并将其插入到文本框中。这部分不起作用,因为 MouseLeftButtonDown 永远不会被解雇。我尝试了几种不同的方法,包括来自本网站的方法 http://www.designerwpf.com/2008/12/03/getting-a-mouseleftbuttondown-or-mouseleftbuttonup- 来自您的文本框的事件/

还有一个我在其他地方看到的 combo.MouseLeftButtonDown += delegate { };

感谢您的帮助。

【问题讨论】:

    标签: wpf combobox


    【解决方案1】:

    代替MouseLeftButtonDown 事件处理程序,使用PreviewMouseLeftButtonDown 可以实现相同的效果。

    【讨论】:

      【解决方案2】:

      您可能想查看SelectionChanged 事件。 It fires whenever an item in the ComboBox's drop down is selected.

      我认为 ComboBox 在内部处理 MouseLeftButtonDown 事件,这导致它不会传递给您的代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多