[英]How to access textbox control located in DataTemplate tags of <phone:PanoramaItem.HeaderTemplate> from code - behind (MainPage.xaml.cs)
i have a textbox located in MainPage.xaml : 我在MainPage.xaml中有一个文本框:
<phone:PanoramaItem.HeaderTemplate>
<DataTemplate>
<TextBox x:Name="src_textbox" Width="400" TextChanged="src_textbox_TextChanged"/>
</DataTemplate>
</phone:PanoramaItem.HeaderTemplate>
now in MainPage.xaml.cs , i want to access src_textbox
in the event handler src_textbox_TextChanged
: 现在在MainPage.xaml.cs中,我想访问src_textbox
在事件处理程序src_textbox_TextChanged
:
the event hanndler is as follows: 事件处理程序如下:
void src_textbox_TextChanged(object sender, TextChangedEventArgs e)
{
string hello = src_textbox.Text();
}
i get red lines under src_textbox
and error says "it is out of current context" . 我在src_textbox
下出现src_textbox
,错误提示“它不在当前上下文中”。
How do i access it ? 我如何使用它?
Yeah I faced the same problem. 是的,我遇到了同样的问题。 Solution: 解:
void src_textbox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox temp_textBox = sender as TextBox;
string hello = temp_textBox.Text();
}
You don't need to add name attribute to your TextBox
control in the xaml. 您无需在xaml中的TextBox
控件中添加名称属性。
Happy Coding!! 快乐编码!
Try this : 尝试这个 :
private void src_textbox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox txtpanorma = (TextBox)sender;
Debug.WriteLine(txtpanorma.Text);
}
TextBox.Text is a Property
not a method
so you cant use ()
for that. TextBox.Text是Property
而不是method
因此您不能使用()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.