WPF popup staysopen=false still keep the popup open while clicking outside

后端 未结 1 1477
醉酒成梦
醉酒成梦 2020-12-21 01:59

my problem here is I made a listbox inside the popup, and set the popup\'s staysopen=false. But each time popup box pops, I have to click something inside the popup(like sel

相关标签:
1条回答
  • 2020-12-21 02:47

    You should create a dependency property in your view model or control for "IsPopupOpen" as shown below to manage state of the popup. Then you can bind both the ToggleButton "IsChecked" and popup "IsOpen" to that DP.

    Also on your ToggleButton, set "Focusable=false" and "IsThreeState=false"

        public bool IsDropDownOpen
        {
         get { return (bool)GetValue(IsDropDownOpenProperty); }
         set { SetValue(IsDropDownOpenProperty, value); }
        }        
    
        public static readonly DependencyProperty IsDropDownOpenProperty =
              DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(Window), new UIPropertyMetadata(false));
    

    Good luck!

    0 讨论(0)
提交回复
热议问题