WPF - TextBlock - Cannot override OnRender

2019-07-30 11:21发布

问题:

I am creating a custom control by deriving TextBlock, my intention is to do some custom rendering based on some dependency properties. However the OnRender method is sealed on TextBlock. Although I can get my work done by overriding OnRenderSizeChanged, this is not correct. Any ideas on how can i do it the right way?

Thanks in advance.

回答1:

In WPF you normally work with styles or Control templates to change the appearance of a control. You can download templates for all controls from Microsoft and play around with them.

Read more here:

http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate(v=VS.100).aspx