简体   繁体   English

如何在移动我的 WinRT/C++ UWP 应用程序的应用程序 window 时关闭 ComboBox 列表项?

[英]How to close ComboBox list items when moving application window of my WinRT/C++ UWP application?

I have a pair of ComboBox controls having IsEditable() true as well as false.我有一对 ComboBox 控件,它们具有 IsEditable() true 和 false。

When I am scrolling through my application or moving my application window (by clicking on the title bar) with list popup open, I would like to close the ComboBox list popup as otherwise there would be a weird delay in aligning the list correctly below the control.当我滚动浏览我的应用程序或移动我的应用程序 window(通过单击标题栏)并打开列表弹出窗口时,我想关闭 ComboBox 列表弹出窗口,否则在控件下方正确对齐列表时会有奇怪的延迟.

Is this possible in UWP with WinRT/C++?在 UWP 中使用 WinRT/C++ 这可能吗? If so, kindly suggest how to.如果是这样,请建议如何。

I did an investigation to find if any events are there to handle in such a scenario when ComboBox control is essentially displaced from initial position while moving the app window/scrolling the app, but couldn't find any help.我进行了一项调查,以了解在移动应用程序窗口/滚动应用程序时 ComboBox 控件基本上从初始 position 移走时是否有任何事件需要处理,但找不到任何帮助。

Edit: Adding ComboBox image from XAML Controls Gallery to demonstrate the behaviour.编辑:添加来自 XAML 控件库的 ComboBox 图像以演示该行为。 In case if IsEditable set as true, when popup is opened and application is scrolled then popup goes outside the window. Instead I would like to dismiss the popup itself.如果 IsEditable 设置为 true,当打开弹出窗口并滚动应用程序时,弹出窗口会超出 window。相反,我想关闭弹出窗口本身。 However, if IsEditable is set as false then we cannot scroll until the popup is dismissed.但是,如果 IsEditable 设置为 false,则在关闭弹出窗口之前我们无法滚动。

在此处输入图像描述

Update: The code I tested for PointerWheelChanged更新:我为 PointerWheelChanged 测试的代码

void CBFile2022X::OnPointerWheelChangedHandler( Windows::Foundation::IInspectable const& sender,
                                               Windows::UI::Xaml::Input::PointerRoutedEventArgs const& eventargs )
    {
         OutputDebugString( L"PointerWheelChanged" );

         if( ComboBox != nullptr )
         {
             ComboBox.IsEnabled( false );
             ComboBox.IsEnabled( true );
         }
    }

I have to say that currently there is no event to detect if the application window is moved or changed its location.我不得不说,目前没有事件可以检测应用程序 window 是否被移动或更改其位置。

Update:更新:

You could handle the UIElement.PointerWheelChanged Event which will be fired when users scroll the mouse wheel.您可以处理UIElement.PointerWheelChanged 事件,该事件将在用户滚动鼠标滚轮时触发。 You could set the IsEnabled property of the ComboBox to false first and then set it to true , this will make the ComboBox lose its focus.您可以先将 ComboBox 的IsEnabled属性设置为false ,然后将其设置为true ,这样会使 ComboBox 失去焦点。 Like:喜欢:

   private void Mypanel_PointerWheelChanged(object sender, PointerRoutedEventArgs e)
    {
        FontsCombo.IsEnabled = false;
        FontsCombo.IsEnabled = true;
    }

Update2:更新2:

If you are using a ScrollViewer you could try to handle the ScrollViewer.ViewChanging Event .如果您使用的是ScrollViewer ,您可以尝试处理ScrollViewer.ViewChanging Event

  private void ScrollViewer_ViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
    {
        FontsCombo.IsEnabled = false;
        FontsCombo.IsEnabled = true;
    }

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

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