WPF - TextBlock - 不能重写OnRender [英] WPF - TextBlock - Cannot override OnRender

查看:815
本文介绍了WPF - TextBlock - 不能重写OnRender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过派生TextBlock来创建自定义控件,我的意图是根据一些依赖属性来做一些自定义的渲染。但是,OnRender方法被封装在TextBlock上。虽然我可以通过覆盖OnRenderSizeChanged来完成我的工作,但这是不正确的。任何想法,我怎么能做到这一点正确的方式?

在此先感谢。

解决方案<在WPF中,您通常使用样式或控件模板来更改控件的外观。您可以从微软下载所有控件的模板,并与他们玩。



阅读更多:

a href =http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate(v=VS.100).aspx =nofollow noreferrer> http:// msdn。 microsoft.com/en-us/library/system.windows.controls.controltemplate(v=VS.100).aspx


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.

解决方案

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

这篇关于WPF - TextBlock - 不能重写OnRender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆