开发者

Force binding to occur after apply ControlTemplate?

Hey, I am building a CustomControl that has a bunch of dependency properties and a few visual parts like, for example, a Canvas, a TextBox, etc. Problem is, upon assigning a value to the dependency properties, I need to perform certain actions on the visual elements, namely I need to add the new dependency property's value to the Canvas, but when the binding kicks in and the 开发者_运维技巧value is assigned, the ControlTemplate has not yet been applied and so it crashes.

What is a good way to fix this?

Thanks.


Simple solution is to do a null check in the dependency property handler to prevent crash, and also override the relevant method in which you know that the visual tree is constructed (OnApplyTemplate most likely) and do the same thing there to initialise your visuals.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜