WPF show small number beside all Controls

91 views Asked by At

I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something allowing me to show a small number besides every one control.

Some text ³

I came with the idea to write a MarkupExtension, where I could write that number like this:

..
<TextBlock Text="Some Text" SomeExtension="3" />
..

and then to add it somehow to the template of the Control.

But I'm sure, you guys have better solution for this problem ;)

2

There are 2 answers

0
decyclone On BEST ANSWER

One way to go with it would be create a Attached Property. Upon setting it on a control, a custom Adorner would be added for that control showing specified number.

0
biju On

Use the tag property to provide the number you want and inside the custom template databind to the property

<TextBlock Text="Some Text" Tag="3" />

and inside the controltemplate

<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}"/>