开发者

WPF show small number beside all Controls

开发者 https://www.devze.com 2023-02-11 05:44 出处:网络
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.

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

精彩评论

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