Skip to main content
Home Forums Silverlight Programming Programming with JavaScript Best way to hide Silverlight control
6 replies. Latest Post by Erick T on November 1, 2009.
(0)
erick t
Member
5 points
9 Posts
10-31-2009 6:26 PM |
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
Contributor
5882 points
1,042 Posts
10-31-2009 6:40 PM |
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.
10-31-2009 11:34 PM |
Does that remove all hit-testing,resizing,etc? It seems too simple... :)
Thanks,Erick
shamrat231
4677 points
595 Posts
11-01-2009 12:48 AM |
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 MahmudSoftware 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.
11-01-2009 4:30 AM |
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.
11-01-2009 5:00 AM |
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.
11-01-2009 5:06 AM |
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.