2010-11-12 34 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 /> 

我在做什么错?我是否正朝着正确的方向前进?

回答

相关问题