I have created nearly 40 to 60 button controls dynamically on canva开发者_StackOverflow中文版s control using WPF. Now I want to remove the selected button control from the canvas. How do I do this.
canvas.Children.Remove(buttonInstance);
Button b=new Button();
b=(Button)sender;
grid.Children.Remove(b);
The easiest would be to just hide it, then you don't have to worry about disposing it as that will be taken care of by the regular life cycle of the controls.
This is the way you can remove control dynamically
Label lbl = (Label)LogicalTreeHelper.FindLogicalNode(mystackpanel, "labelname");
mystackpanel.Children.Remove(lbl);
精彩评论