I am creating Dynamic Rectangle and adding into StackPanel. I need to add text to each rectangle. How can I do that?
I am creating Dynamic Rectangle and adding into StackPanel . I need to add
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A Rectangle doesn’t have any child content, so you will need to put both controls inside of another panel, such as a grid:
You can also use a Border control, which will take a single child and draw a rectangle around it:
You say “dynamic rectangle”, so it sounds like you are doing this in code. The equivalent C# would look something like this:
But if you want a dynamic list of rectangles, you should probably use an ItemsControl:
If you set the DataContext to a list of objects, this XAML will create a Border with a TextBlock for each one with the text set to the Text property on the object.