1

I've found this answer which explains how to arrange a collection of rectangles inside a grid in XAML:

<Grid... >
    <Rectangle Grid.Column="0"
               Grid.Row="0"  
               Stroke="Blue"
               Fill="Transparent" />
        <TextBlock Grid.Column="0" 
                   Grid.Row="0"
                   Text="(0,0)" />
    </Rectangle>
    ...
</Grid>

Now I'm trying to do the same in C#, and I've found out that Rectangle doesn't have a Content property. So how do I add a TextBlock to a Rectangle?

Community
  • 1
  • 1
Ramy Al Zuhouri
  • 20,942
  • 23
  • 94
  • 176

1 Answers1

4

You could use a Border instead of a Rectangle, since Border.Content does exist.

Instead of setting Rectangle.Stroke and Rectangle.Fill you would set Border.BorderBrush and Border.Background.

Jashaszun
  • 8,903
  • 3
  • 21
  • 51