Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to add multiple dynamic buttons in wpf using c# .. The buttons will be added through database. ..

What I have tried:

I searched in the internet but i couldn't find any solution.
Posted
Updated 8-Apr-21 4:11am
Comments
Richard MacCutchan 8-Apr-21 7:10am    
Buttons are Windows controls, you can create them any time and add then to your form. What do you mean by "The buttons will be added through database"?
[no name] 8-Apr-21 12:13pm    
Or ... just toggle their visibility.

1 solution

This isn't an easy question to answer because we don't know anything about your application. What I can do is summarise what you need to consider:

- You'll need a way to get the button definitions from the database
- You'll need to create an observable collection which you can bind to the UI
- You'll need a container which can use a template to render items
- You'll need to bind the collection to the container and build the WPF template
- You'll need to add any appropriate button click handlers

How to: Create and Bind to an ObservableCollection - WPF .NET Framework | Microsoft Docs[^]
The ItemsControl - The complete WPF tutorial[^]
Using WPF commands - The complete WPF tutorial[^]

These might be good starting points for the WPF side. For the database side, it depends on what framework you're using, your database structure, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900