Reputation: 420
I have a silverlight project which contains 2 silverlight controls Control_1 and Control_2. Please note that its in same app.Now I have asp.net project which will use any of these silverlight control (either Control_1 or Control_2).
Challenge is how do I tell silverlight which control to load. I used param property in html object to pass the parameters and tell the app which control to load at runtime?
But what if there are more than 2 controls in same project? We cannot have a long switch case statement in the app file only to load the controls. Is there any better way?
Upvotes: 0
Views: 669
Reputation: 5968
No, There isn't, and this is not about Silverlight itself, this is normal logic.
In your App.xaml file, put this:
using System.Windows; // Application, StartupEventArgs
namespace SilverlightApplication
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}
private void Application_Startup(object sender, StartupEventArgs e)
{
// Specify the main application UI
if(SomeCondition == true)
this.RootVisual = new Control1();
else
this.RootVisual = new Control2();
// In the same way, you may define a switch statment
}
}
}
You may decide what that condition is by passing parameters to the XAP file, and finally you access those by accessing e.InitParams
in Application_Startup
For more info: Application.RootVisual
Upvotes: 1