Add Controls to GroupBox which was created dynamically

Posted by phil13131 on Stack Overflow See other posts from Stack Overflow or by phil13131
Published on 2012-06-28T21:13:22Z Indexed on 2012/06/28 21:15 UTC
Read the original article Hit count: 164

Filed under:
|
|
|

I add GroupBoxes to an ItemsControl dynamically using:

string name_ = "TestName", header_ = "TestHeader"
GroupBox MyGroupBox = new GroupBox { Name = name_, Header= header_, Width = 240, Height = 150, Foreground=new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)) };

MyItemsControl.Items.Add(MyGroupBox);

Now I need to add content to this GroupBox, like a few TextBlocks created like:

TextBlock MyTextBlock = new TextBlock {Text = "test"};

But I can't figure out how to do that. Normally to a Grid or something like that I would just use .Children.Add(MyTextBlock), but that doesn't work here.

Also I have to be able to remove specific Items from the ItemsControl again (best would be by the name of the Item, name_ in this example).

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf