how would i add multiple buttons to a window in c#? here's what i need to do... i'm getting multiple user values from a dictionary (within reason, only @ 5-6 values). for each value, i need to create a button. now, how do i name the button, not the text within the button? how do i define the "click" method for each button (they will all be different)? and how do i erase the button if i don't want it anymore?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
I would encapsulate the whole thing, there normally should be no point in naming the button. Something like this:
Then you can create models and put them into a bindable collection:
Then you just need to add and remove items from that and create buttons on the fly:
For more info see relevant articles on MSDN:
Data Binding Overview
Commanding Overview
Data Templating Overview
Consider you have a
StackPanel
named spTo remove button you could do
Hope this help.
Xaml code:
Code-behind: