C# 在页面wp7之间传递数据

C# 在页面wp7之间传递数据,c#,xaml,windows-phone-7,datatemplate,C#,Xaml,Windows Phone 7,Datatemplate,我有个小问题。 我有这样一个数据模板: <phone:PhoneApplicationPage.Resources> <DataTemplate x:Key="DangersItemTemplate"> <Grid Height="102" Width="447" Tap="Grid_Tap"> <Image Name="image" Source="{Binding Image}" Horizon

我有个小问题。 我有这样一个数据模板:

    <phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="DangersItemTemplate">
        <Grid Height="102" Width="447" Tap="Grid_Tap">
            <Image Name="image" Source="{Binding Image}" HorizontalAlignment="Left" Width="90" />
            <TextBlock Name="text" Text="{Binding Nom}" TextWrapping="Wrap" Margin="102,16,16,22"/>
        </Grid>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>
我想在CSharp代码中使用Textlock控件将Text属性传递到第二个xaml页面,但是我找不到该控件的名称,它无法访问


有什么想法吗?

我只使用VB.Net,但我相信您可以转换。 只需在应用程序中使用任何共享变量。 在这里,您可以在源代码示例中看到它:

只需使用公共共享的MyText作为字符串 在应用课上。您可以在任何地方访问此文件。 您还可以使用来绑定该共享属性

或者,您可以使用导航查询。请在此处阅读更多信息:


绑定文本块的文本,因此必须在datacontext中具有该值。我会将此值添加到QueryStarng并导航到该页面

var text = ((Whatever) DataContext).Nom;
string page2Uri = string.Foramt("/PAge2.xaml?Nom={0}", text);
NavigationService.Navigate(new Uri(page2Uri, UriKind.Relative));
然后,要从查询字符串中获取数据,可以在页面中使用OnNavigatedTo方法,然后检查这个.NavigationContext.querystring[nom]

或者看看MVVM模式之类的东西