2011-02-01 102 views
0

我有一个silverlight项目,其中包含2个Silverlight控件Control_1和Control_2。请注意,它在同一个app.Now我有asp.net项目将使用任何这些silverlight控件(Control_1或Control_2)。在asp.net页面中加载silverlight控件

挑战是如何告诉silverlight哪个控件要加载。我在html对象中使用param属性来传递参数并告诉应用程序在运行时加载哪个控件?

但是如果在同一个项目中有两个以上的控件呢?我们在应用程序文件中只能加载控件的情况下不能有长的开关箱语句。有没有更好的方法?

回答

1

不,没有,这不是关于Silverlight本身,这是正常的逻辑。

在你App.xaml文件,把这个:

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 
     } 
    } 
} 

你可以决定的条件就是通过传递参数给XAP文件,最后你Application_Startup

访问那些通过访问e.InitParams欲了解更多信息:Application.RootVisual

+0

有什么办法可以避免这种开关的情况下,这是唯一的方法来实现?? – 2011-02-01 11:39:39