开发者

WPF show small number beside all Controls

I have many FrameworkElements (TextBlock, Ch开发者_运维问答eckBox, 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 ;)


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.


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}"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜