开发者

OnApplyTemplate method does not get called when the custom control is being rendered

I have made a custom control for windows phone 7.

If I use this control in XAML code, it shows up in both the designer and the emulator.

But if I create in C# code and render it in a WriteableBitmap, nothing shows up in the WriteableBitmap, and the OnApp开发者_如何学GolyTemplate does not get called either.

I tried calling the ApplyTemplate method and the Measure and Arrange methods, but none of them can make the control to be rendered.

So what is the right approach to make a custom control renderable in a WriteableBitmap?

Thanks.


Before a WPF template is applied, which includes Silverlight, an object must be added to a visual tree. Calling ApplyTemplate will simply fail if the object isn't in a visual tree. So to make it render properly, add it to a visual tree, then you can call ApplyTemplate / UpdateLayout / etc. and have it render correctly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜