开发者

How do I delete dynamically created button control from canvas using WPF

开发者 https://www.devze.com 2022-12-11 03:43 出处:网络
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.can

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消