Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border with more then one child

Tags:

c#

wpf

I have a Border.

I have a TextBlock displayed on it:

TextBlock tb = new TextBlock();
myBorder.Child = tb;

And it works fine.

The thing is: I also want to have CheckBox displayed on it.

The problem is that border is a single child element.

Is there any workaround here?

Thank you!

like image 582
Jacek Wojcik Avatar asked Dec 21 '22 00:12

Jacek Wojcik


1 Answers

The problem is that border is a single child element...

Correct, Border is a ContentControl and they, by design, can only contain 1 child.

So... is there any workaround here?

Yes, just place a Grid, StackPanel or any other LayoutControl (Panel) inside the Border. This is a general approach that lets you create arbitrary complex content.

like image 175
Henk Holterman Avatar answered Dec 28 '22 22:12

Henk Holterman