Skip to main content

Microsoft Silverlight

Answered Question Best way to hide Silverlight controlRSS Feed

(0)

erick t
erick t

Member

Member

5 points

9 Posts

Best way to hide Silverlight control

I have a situation where there is a div that will contain either a Silverlight control or some HTML. The Silverlight control is the navigation, and the HTML contains the details. For background, the application is a ASP.NET MVC application.

My first thought is to have two child divs, one with the HTML content, one with the Silverlight content, then write a little JS to hide/show the correct one. This works fine, but I am wondering if it is the best way. What should I do to the Silverlight control before _hiding_ it so that it won't use any more resources than needed? What should I do before showing the Silverlight again so that the user is up and running quickly?

If this example doesn't make sense, I can put together a simple repo.

Thanks!

Erick

Sledge70
Sledge70

Contributor

Contributor

5882 points

1,042 Posts

Answered Question

Re: Best way to hide Silverlight control

Probably the most basic thing you could do is to collapse the visibility of your root object in the visualtree. This will at least tell the rendering side of things to do no processing.

______________________________________________________
Please mark replies as answers if they answered your question...

Flexman on Silverlight

erick t
erick t

Member

Member

5 points

9 Posts

Re: Best way to hide Silverlight control

Does that remove all hit-testing,resizing,etc? It seems too simple... :)

Thanks,
Erick

shamrat231
shamrat231

Contributor

Contributor

4677 points

595 Posts

Re: Best way to hide Silverlight control

Hi, as long as the SL object in the page, it will load, whether u hide/ show using js. The idea is to not have te SL object in the page at first place. When u r showing it, have a iframe instead and use js populate the iframe.src to show the SL content which is some another page. When u r hiding it, set iframe.src = "", sl page will go away.

look here for more info.

http://forums.silverlight.net/forums/p/138485/310433.aspx#310433

Please 'Mark as Answer' if it was helpful

Sharker Khaleed Mahmud
Software Developer
(MCP,MCTS,MCPD[web])

This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.

 

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog

erick t
erick t

Member

Member

5 points

9 Posts

Re: Best way to hide Silverlight control

The problem with this approach is that I want the SL control to load. The work-flow will go from the Silverlight Control to an AJAX call that populates a div with HTML from the AJAX call, then back to the SL control, and so on. I want to make sure that the hit of loading the SL control only occurs once, which is why I want to hide it, then show it again.

Thanks,
Erick

Sledge70
Sledge70

Contributor

Contributor

5882 points

1,042 Posts

Re: Best way to hide Silverlight control

It is simple but effective. It doesn't remove your items from the visual tree but it tells SL not to bother checking the control for any rendering etc. If you want to only load your control once this would be the best way to do.

A common mistake is to set the opacity to 0 to hide controls but then you still get the processing hit.

______________________________________________________
Please mark replies as answers if they answered your question...

Flexman on Silverlight

erick t
erick t

Member

Member

5 points

9 Posts

Re: Best way to hide Silverlight control

Thanks, this seems like the best answer. It won't render, so I'm hoping it won't hit-test either. Let me know if you know otherwise.

Thanks,
Erick

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities