简体   繁体   中英

programmatically making a dropdown menu in vb.net WPF

I'm making a custom dropdown button (since the one included in wpf requires too much hacking to style right). Now that i got the button bit out of the way i need to add the drop down part.

My first thought was to add a stackpanel and use that to contain the items but it gets cut off if it leaves the borders of the grid that the button is in. Next up was the popup primitive, it gets on top of everything nicely enough but position wise it just free floats and i haven't figured out how to make it follow the button it was spawned by. I also tried using contextmenu but that seems to have no positioning controls at all and just sits where the mouse made it..

Anyways wpf is a big package and I'm just getting into it, anybody know which direction i might find what I'm looking for?

Preferred approach normally is to use a Popup . You got two very important properties with a Popup

PlacementTarget and Placement

Setup a binding for PlacementTarget on the Popup to your custom Button and then use Placement to position the Popup accordingly wrt to the PlacementTarget ( Button )

Placement accepts an enum of type PlacementMode which gives you quite a few options to position the Popup .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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