How to always place PopUp under a ToggleButton in WPF

后端 未结 1 1069
一整个雨季
一整个雨季 2021-01-20 11:22

I want to place a popup under a togglebutton when I click on it. In this popup I want to add button and other controls. But how can I make sure that the popup window always

相关标签:
1条回答
  • 2021-01-20 11:29

    Use Placement and PlacementTarget properties of the Popup :)

    <Popup Placement="Bottom" PlacementTarget="{Binding ElementName=myToggleButton}" IsOpen="{Binding IsChecked, ElementName=Userbtn}" StaysOpen="False" />
    

    The thing to note here is that, if the window is moved when Popup is open, it wont move along.. What you could do is Bind the IsOpen property to ToggleButton's IsChecked and set StaysOpen=False. Doing that, the Popup will close automatically, toggling the button back :) , also you wont be needing the C# code if you are to do this :)

    OR here is a link to another SO post if it should stay open whatever the case be : Move a WPF Popup

    Hope it helps :)

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