开发者

How to make parametrizable properties in WPF user controls?

I want to refactor many similar controls that only differ in the value of a single property (besides positioning properties).

Imagine that I have an user control (let's call it UC1) that have a Label. The Label.Content should be value + ":" where value is passed through a Property to the user control.

I could implement it by hand using the Initialized event, but it happens that in my case it isn't a Lab开发者_如何转开发el but a custom control (let's call it UC2) which itself needs the property on its own Initialized event.

Somehow the UC2 Initialized runs before the UC1's, and it throws an exception because the property value is not set yet.

How to solve this?


Maybe the problem is cause by calling InitializeComponent() inside the user control when it shouldn't.

It may cause the Initialized event to be fired twice.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜