如何获取对象的名称并使用其名称更改文本框的文本姓名?
你好(wp7 应用程序的开发人员)。
以下问题已经让我无数个不眠之夜,所以我希望有人能为我提供解决方案。
分组为网格的元素应该调用(点击)一个函数,该函数用我声明的文本更改文本框的文本。
我已经有了读取对象“名称”的功能:
private void FunctionABC(object sender, System.Windows.Input.GestureEventArgs e)
{
//Objects name
string ObjectSender = (sender as Grid).Name.ToString();
//But how to continue, if I want kind of "this" result?:
this.ObjectSender.Text = "abc";
}
我很感谢任何回答我的问题。谢谢。
Hi there (developers of wp7 apps).
The following problem already caused countless sleepless nights, so i hope anyone could provide me with a solution.
Elements grouped as a grid should call (on tap) a function that changes a textbox' text with one i declare.
I already have the function that reads the "name" of the object:
private void FunctionABC(object sender, System.Windows.Input.GestureEventArgs e)
{
//Objects name
string ObjectSender = (sender as Grid).Name.ToString();
//But how to continue, if I want kind of "this" result?:
this.ObjectSender.Text = "abc";
}
I appreciate any answer my problem. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的问题是,如果您点击网格,如何更改放置在网格内的 textbox.text 属性,那么您应该迭代网格子项并找到您正在查找的文本框,然后更改其文本属性。
首先,您需要更改此行:
string ObjectSender = (sender as Grid).Name.ToString();
因为这一行为您提供了网格的名称,而不是网格本身。
网格对象发送者=(网格)发送者;
然后你可以搜索它的孩子。
If your question is how to change the textbox.text property which is placed inside a grid if you tap the grid then you should iterate through the grids Children and find the textbox you are looking for and then change it's text property.
First of all you need to change the this line :
string ObjectSender = (sender as Grid).Name.ToString();
because this line gives you the name of the Grid and not the Grid itself.
Grid ObjectSender = (Grid) sender;
And then you can search through it's children.