传递字符串到用户控件 [英] passing a string to a User Control

查看:126
本文介绍了传递字符串到用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接近地铁应用世界在这个日子里,请温柔。
这里的问题:



页面接收到来自另一个页面字符串

 保护覆盖无效的OnNavigatedTo(NavigationEventArgs E)
{
Title.Text = e.Parameter.ToString();
}

和我需要这个字符串传递到接收页面的用户控制。



如何传递从页面的参数到另一个页面?


解决方案<的用户控件/ DIV>

这样的:



属性添加到您的用户控件:

 公共字符串MYTEXT {搞定;组; } 



给你的用户控件的名称。

 < SRC:TopBarControl X:NAME =MyTopBarControl/> 



然后用你的NavigatedTo方式:

 保护覆盖无效的OnNavigatedTo(NavigationEventArgs E)
{
VAR _TextParam = e.Parameter.ToString();
this.MyTopBarControl.MyText = _TextParam;
}

这会养活你的用户控制它所需要的。



您也可通过参数设置为页面的某些公共财产绑定到它。如果尝试这种方法,请记住,使用户控件的属性依赖项属性,而不是一个CLR属性。我写了一篇文章绑定,如果你想要一个更好的交代的http:/ /blog.jerrynixon.com/2012/10/xaml-binding-basics-101.html



祝你好运!


I'm approaching to Metro App world in this days, please be gentle. Here's the problem:

a page receives a string from another page

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Title.Text = e.Parameter.ToString();
}

and I need to pass this string to an User Control of the receiving page.

How can I pass a parameter from a page to an UserControl of another page?

解决方案

Like this:

Add a property to your user control:

public string MyText { get; set; }

Give your user control a name.

<src:TopBarControl x:Name="MyTopBarControl" />

Then use your NavigatedTo method:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var _TextParam = e.Parameter.ToString();
    this.MyTopBarControl.MyText = _TextParam;
}

This will feed your User Control what it needs.

You could also bind to it by setting the parameter to some public property of the page. If you attempt this approach, please remember to make the User Control's property a Dependency property and not a CLR property. I wrote an article on binding if you want a better explaination http://blog.jerrynixon.com/2012/10/xaml-binding-basics-101.html

Best of luck!

这篇关于传递字符串到用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆