Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/windows-phone-8/2.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
Windows phone 8 访问DataTemplate中定义的StackPanel_Windows Phone 8_Datatemplate_Longlistselector - Fatal编程技术网

Windows phone 8 访问DataTemplate中定义的StackPanel

Windows phone 8 访问DataTemplate中定义的StackPanel,windows-phone-8,datatemplate,longlistselector,Windows Phone 8,Datatemplate,Longlistselector,我有一个LongListSelector,根据用户的选择,根据收到的数据为其选择适当的DataTemplate。 我在页面的参考资料中定义了其中3个数据模板,并在填充我的LongListSelector之前使用以下方法设置了相应的数据模板: RoutesLongListSelector.ItemTemplate = Resources["SecondItemTemplate"] as DataTemplate; 在这些DataTemplates中有一个元素—StackPanel—在填充列表后,

我有一个LongListSelector,根据用户的选择,根据收到的数据为其选择适当的DataTemplate。 我在页面的参考资料中定义了其中3个数据模板,并在填充我的LongListSelector之前使用以下方法设置了相应的数据模板:

RoutesLongListSelector.ItemTemplate = Resources["SecondItemTemplate"] as DataTemplate;
在这些DataTemplates中有一个元素—StackPanel—在填充列表后,我在其中添加了一些子元素

<StackPanel x:Name="MyStations" Grid.Column="1" Grid.Row="1">
</StackPanel>

因此,当我试图使用它的名称来添加子项[MyStations.children.add(…)]时,我得到一个错误:“MyStations”在当前上下文中不存在。 我试图在页面的ContentPanel中将其中一个模板设置为默认模板,但仍然收到相同的错误

似乎是个小问题,但我想不出什么。
有什么建议吗?

您不能使用
Name
属性访问
DataTemplete
的UI元素,即
x:Name
。您可以使用它的加载事件来访问它。请具体说明您的要求


private void MyStations\u已加载(对象发送方,路由目标)
{
var_StackPanel=(StackPanel)发送方;
}

数据模板中的元素不能通过名称直接访问。