Skip to main content

Microsoft Silverlight

Answered Question Which event to buckle control to Page code?RSS Feed

(0)

Shunyata Kharg
Shunyata...

Member

Member

2 points

17 Posts

Which event to buckle control to Page code?

 Hello!

 I'm in the process of developing a control which I've derived from UserControl. My control has a canvas which I added at designtime and what needs to be drawn is added to the Children property of the canvas in a method I've called Draw(). All fine so far.

 However, in my case, what needs to be drawn will depend on how my control is coded in the constructor of the Page in which my control sits. At the moment, my code looks like this:

public Page()
{
    InitializeComponent();
    this.MyControl.DrawASeriesOfElements = true;
    this.MyControl.Draw();
}

what I want to do is eliminate the call to MyControl.Draw() in the constructor. I understand that there's no OnRender() in Silverlight, but I'm not sure which event I have to get my control to subscribe to make the call to Draw() unnecessary. The ones I have tried (LayoutUpdated and ArrangeOverride) do not produce the same results as calling my Draw() method (obscure errors are thrown in MyControl's code).

 Any ideas please? Or will have have to oblige my clients to call my Draw() method everytime they make changes to MyControl?

Many thanks!

Thank you!

sladapter
sladapter

All-Star

All-Star

17439 points

3,172 Posts

Answered Question

Re: Which event to buckle control to Page code?

You can call this.Draw() in your MyControl.Loaded event. So when your control is loaded to a Page, it draws itself. 

 

sladapter
Software Engineer
Aprimo, Inc

Please remember to mark the replies as answers if they answered your question

Shunyata Kharg
Shunyata...

Member

Member

2 points

17 Posts

Re: Which event to buckle control to Page code?

Hello,

sladapter:

You can call this.Draw() in your MyControl.Loaded event. So when your control is loaded to a Page, it draws itself. 

 

 Perfect, thank you. That looks like being the one!

 Thank you!

Thank you!
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities