2012-06-18 18 views
0

我創建了一個作爲我的主要silverlight頁面運行的Silverlight業務應用程序。對於我的「菜單」上的每個超鏈接按鈕,我啓動另一個在Visual Studio中創建爲另一個項目的Silverlight應用程序。這些是非商業應用程序。在Silverlight應用程序之間傳遞值

一切正常。不過,我試圖從我的主要SL應用程序中傳遞一個值給SL應用程序。 我一直在使用谷歌搜索很多,無法找到答案。 據我所知,在ASP和SL之間使用InitParam,而不是在SL應用之間使用。 由於應用程序配置爲第一個SL應用程序和第二個應用程序的應用程序配置從未啓動,我無法使用(這至少是我的理解)

我想傳遞的值是登錄名和角色,可以從Silverlight Business應用程序的webcontext中獲取,但我無法在內部運行的非Business應用程序中獲取webcontext。

這是我啓動我的SL應用程序中的主要SL內部應用程序:

public Customers() 
    { 
     InitializeComponent(); 

     this.Title = ApplicationStrings.CustomersPageTitle; 

     if (WebContext.Current.User.IsInRole("Users") || WebContext.Current.User.IsInRole("Administrators")) 
     { 
     WebClient client = new WebClient(); 
     client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted); 
     client.OpenReadAsync(new Uri("customers.xap", UriKind.Relative)); 
     } 
    } 

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    { 
     string appManifest = new StreamReader(Application.GetResourceStream(new StreamResourceInfo(e.Result, null), 
      new Uri("AppManifest.xaml", UriKind.Relative)).Stream).ReadToEnd(); 

     XElement deploymentRoot = XDocument.Parse(appManifest).Root; 
     List<XElement> deploymentParts = 
      (from assemblyParts in deploymentRoot.Elements().Elements() select assemblyParts).ToList(); 

     Assembly asm = null; 
     AssemblyPart asmPart = new AssemblyPart(); 
     foreach (XElement xElement in deploymentParts) 
     { 
      string source = xElement.Attribute("Source").Value; 
      StreamResourceInfo streamInfo = Application.GetResourceStream(new StreamResourceInfo(e.Result, "application/binary"), new Uri(source, UriKind.Relative)); 

      if (source == "customers.dll") 
      { 
       asm = asmPart.Load(streamInfo.Stream); 
      } 
      else 
      { 
       asmPart.Load(streamInfo.Stream); 
      } 
     } 

     UIElement myData = asm.CreateInstance("customers.MainPage") as UIElement; 
     stackCustomers.Children.Add(myData); 
     stackCustomers.UpdateLayout(); 
    } 

有人嗎?

+0

我不得不問 - 你爲什麼讓他們單獨的應用程序而不是主應用程序中的頁面?如有必要,您可以使用Prism模塊化應用程序。 – ChrisF

回答

0

我同意ChrisF,我認爲棱鏡或MEF可以解決你的問題。 任何方式,做網絡上的一些搜索,看看這兩個類: **

LocalMessageSender 
LocalMessageReceiver 

**

好運

相關問題