I have a application which generate rectangles dynamically and which are clickable with the help of MouseLeftbuttonDown event. I want to add some text(different) to each of the rectangles. I have tried encapsulating rectangle and a textblock in a grid and than adding that grid to canvas; but the click stopped working. Help!!
Asked
Active
Viewed 149 times
-2
-
How is this different to your last question? http://stackoverflow.com/questions/23766927/adding-text-to-a-dynamic-and-clickable-rectangle – Daniel Kelley May 20 '14 at 18:08
-
The functionality in last question works fine. That was to get the click for multiple rectangles. And here we know that rectangles are not the containers so we can't add text directly on them. We need some workaround. I tried one such workaround and that failed. See if you can help. – Ram Murti May 20 '14 at 18:14
-
Please (again) delete all your code and learn MVVM before you ever write a single line of code in WPF. – Federico Berasategui May 20 '14 at 18:15
-
Appreciate your guidance #Highcore. You said you will send some sample code. Looking forward for your help. – Ram Murti May 20 '14 at 18:17
-
you wanted text inside a rectangle ? – N.J May 20 '14 at 18:38
-
@user1767798 yes sir. – Ram Murti May 20 '14 at 18:40
1 Answers
0
if i have to do this then i would do something like
<Rectangle Width="100" Height="30" Stroke="Black" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown">
<Rectangle.Fill>
<VisualBrush>
<VisualBrush.Visual>
<TextBlock Text="SomeText"/>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
I dont know what you exactly want but from the question i figured something like this

N.J
- 1,172
- 3
- 11
- 19