开发者

Codebehind for ControlTemplate of lookless control?

开发者 https://www.devze.com 2023-04-01 06:50 出处:网络
I\'m writing a lookless control which uses the usual Generic.xaml to apply a default control template.

I'm writing a lookless control which uses the usual Generic.xaml to apply a default control template.

This control template needs some codebehind in order to render itself (Mainly to respond to resize events), but I'm confused where the heck I'm 开发者_如何学运维supposed to put the code, and how I access the template from it.

This code is for rendering this particular template only, so does not belong in the control itself.

Can anyone give me a clue?


Here's a link that might help you


You can override the OnRender method in your Control, just like in a UserControl. The element in your ControlTemplate though will appear on top of anything rendered by your Control.

If you need to add custom rendering above or in between elements in your ControlTemplate, then you'd have to use a secondary element as a named part. An example of named parts can be found in this blog or in mdm20's link (search for "PART_").

You'd then have that secondary element perform the rendering, possibly based on settings passed down from your control.


I have found an excellent link that solves this using an attached behaviour on the template to attach a ViewModel that provides the extra functionality. This way the control itself remains completely unaware of any template specific logic:

http://www.scottlogic.co.uk/blog/colin/2010/08/developing-a-very-lookless-silverlight-radial-gauge-control/

0

精彩评论

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