Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从ListViewItem';数据模板_C#_Xaml_Listview_Windows Phone 8.1 - Fatal编程技术网

C# 如何从ListViewItem';数据模板

C# 如何从ListViewItem';数据模板,c#,xaml,listview,windows-phone-8.1,C#,Xaml,Listview,Windows Phone 8.1,我不知道在点击按钮后如何从“firstBox”和“secondBox”中获取文本 下面是如何获取文本 String text1 = firstBox.Text; String text2 = secondBox.Text; 注意:firstBox和secondBox必须是类成员,才能在不同的类方法中使用它们。有很多方法可以做到这一点,例如,您可以遍历单击按钮父级的VisualTree,并使用所需的名称检索TextBox。在本例中,我将利用由编写的扩展方法 例如,它可以如下所示: priv

我不知道在点击按钮后如何从“firstBox”和“secondBox”中获取文本



下面是如何获取文本

 String text1 = firstBox.Text;
 String text2 = secondBox.Text;

注意:
firstBox
secondBox
必须是类成员,才能在不同的类方法中使用它们。

有很多方法可以做到这一点,例如,您可以遍历单击按钮父级的VisualTree,并使用所需的名称检索TextBox。在本例中,我将利用由编写的扩展方法

例如,它可以如下所示:

private void按钮\u单击\u 1(对象发送者,路由目标)
{
var parent=(发送者作为按钮)。parent;
TextBox firstOne=parent.GetChildrenOfType().First(x=>x.Name==“firstBox”);
Debug.WriteLine(firstOne.Text);
}
请记住将扩展方法放在静态类中的某个位置:

公共静态类扩展
{
公共静态IEnumerable GetChildrenOfType(此DependencyObject开始),其中T:class
{
//代码的其余部分

查看此问题和Jerry的答案