2010-11-12 46 views
0

在Silverlight用戶控件的文件後面的代碼中有一個方法,我應該向其傳遞一個字符串參數。我正在嘗試以下方法,但出現錯誤System.Collections.Generic.KeyNotFoundException Message =在字典中找不到密鑰。將參數傳遞給Silverlight用戶控件

public partial class MyUserControl : UserControl 
{ 
    public MyUserControl() 
    { 
     InitializeComponent(); 
     string strid = HtmlPage.Document.QueryString["id"]; // this way it doesn't work 
     ReadAndUpdate(strid); 
    } 

    private void ReadAndUpdate(string shid) 
    { 
      //some stuff here 
    } 
.......... 

,我把這個頁面如下所示:

 string idstr = xxxx; // my value 
     this.NavigationService.Navigate(new 
        System.Uri("/MyPage?id=" + idstr, System.UriKind.Relative)); 

和上面的Uri字符串出現在瀏覽器中按預期(如果我不試圖解析它在我的用戶控件初始化)。

的MyUserControl被稱爲在我的頁面XAML(在我瀏覽到):

<uc:MyUserControl /> 

我在做什麼錯?我是否正朝着正確的方向前進?

回答

相關問題