[英]Passing a parameter to a Silverlight user control
In a Silverlight User Control's code behind file there is a method, to which I should pass a string parameter. 在Silverlight用户控件的文件后面代码中,有一个方法,我应该向该方法传递字符串参数。 I'm trying the following way but get an error System.Collections.Generic.KeyNotFoundException Message=The key is not found in the dictionary.
我正在尝试以下方式,但收到错误System.Collections.Generic.KeyNotFoundException Message =在字典中找不到密钥。
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
}
..........
and I call this page like the following: 我将这个页面称为如下:
string idstr = xxxx; // my value
this.NavigationService.Navigate(new
System.Uri("/MyPage?id=" + idstr, System.UriKind.Relative));
And the above Uri string is appeared in browser as intended (if I'm not trying to parse it in my UserControls' initialization). 上面的Uri字符串按预期显示在浏览器中(如果我不尝试在UserControls的初始化中解析它的话)。
MyUserControl is called in the MyPage XAML (where I navigate to): 在MyPage XAML(我导航到的位置)中调用MyUserControl:
<uc:MyUserControl />
What am I doing wrong? 我究竟做错了什么? Am I moving in the right direction at all?
我是否完全朝着正确的方向前进?
what about using initParams ? 使用initParams呢? http://www.dotnetspider.com/Silverlight-Tutorial-313.aspx
http://www.dotnetspider.com/Silverlight-Tutorial-313.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.