Dynamically adding dynamic buttons to <wrappanel> or <stackpanel> or whatever else?

PatM

Well-known member
Joined
Dec 5, 2012
Messages
52
Programming Experience
10+
I've been searching all morning for examples of how to create dynamic buttons for a wpf control. I was thinking of a wrappanel at first but then thought a stackpanel would probably be better anyway.

Lots of C# examples but nothing for vb.net
 
If you have C# examples then you have the principles, so you can simply translate the code to VB. The principles don't change and the code likely won't change much either. If you need help translating specific parts of the C# code, you can ask about them here. That said, you can download and install Instant VB to convert blocks of code with a high degree of accuracy/integrity.
 
Thanks, I did use c# for a few years but have pretty much forgotten most of it.
Luckily I finally found a simple xaml example and decided to just try and write the vb myself. As long as you give the itemscontrol or whatever xaml control you are using the right name and set it's x:Name properly and set thex:name.itemssource to an observable list it simply works.

Observable lists required importing System.Collections.ObjectModel before I could declare them of course.
 
Observable lists required importing System.Collections.ObjectModel before I could declare them of course.
Nope. You need to import a namespace if you want to use a type name unqualified but you can use the full-qualified type name in code. Importing namespaces doesn't change anything about what types you have access to - that's referencing the appropriate assembly - it simply allows you to write more succinct code, without qualifying type names everywhere.
 
I did finally figure out how to do it. I used an ItemsControl with a binding when added buttons generated in the codebehind. Of course I ended up deleting the project later without thinking so I have to figure it out again. The only problem I had really was that all the examples I could find had far more complexity than I needed or could easily understand. I just found one that worked and started cutting away all the extras until I had a simple wrappanel that showed the buttons.
 

Latest posts

Back
Top