Jake Freelander
Jake Freelander

Reputation: 1471

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?

Upvotes: 0

Views: 591

Answers (1)

Viv
Viv

Reputation: 17380

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 w.r.t to the PlacementTarget(Button)

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

Upvotes: 1

Related Questions