Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.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# 将标记字段传递给其他视图wf7_C#_Windows Phone 7_View - Fatal编程技术网

C# 将标记字段传递给其他视图wf7

C# 将标记字段传递给其他视图wf7,c#,windows-phone-7,view,C#,Windows Phone 7,View,好的,我需要将此代码中的标记传递到下一页,但我不知道如何访问它。有人能帮忙吗 代码: <ListBox x:Name="AgendaList" Width="450" Height="520" Margin="10" SelectionChanged="event_SelectionChanged"> <ListBox.ItemTemplate> <DataTemplate>

好的,我需要将此代码中的标记传递到下一页,但我不知道如何访问它。有人能帮忙吗

代码:

 <ListBox x:Name="AgendaList" Width="450" Height="520" Margin="10" SelectionChanged="event_SelectionChanged">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image  Width="100" Stretch="Uniform" HorizontalAlignment="Center" Source="/SuperAgenda;component/Images/calendar.jpg" />
                            <TextBlock  Text="{Binding Title_}" Tag="{Binding EventId_}" />

                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
任何帮助都很好,谢谢。

实际上,要在页面之间传输数据,您应该使用PhoneApplicationService类

 PhoneApplicationService.Current.State["field"] = someField;
在您的按钮点击/点击事件

然后,在下一页中,使用cast获取该值

someField = (fieldType)PhoneApplicationService.Current.State["field"];
这就是您想要的吗?

只需使用您导航到的页面的属性即可

if (this.NavigationContext.QueryString.ContainsKey("ProductId"))
{
    productID = this.NavigationContext.QueryString["ProductId"];
}
else
{
    productID = App.Current.Resources["FeaturedProductID"].ToString();
}

在这里使用
标记
属性是多余的,因为绑定控件中的
数据模板
包含对象的所有属性。使用
DataContext
检索对象。将
Tap
事件添加到
DataTemplate
中的
StackPanel
(以便用户可以点击图像或文本):


然后使用paiden答案中的
NavigationContext
检索接收页面上的值。

很好。我需要将标签的值发送到下一页。基本上,我需要知道所选的事件id,并将其发送到下一页以显示该事件。谢谢你的想法,但我不认为这是我需要的。我只需要将标签的值发送到下一页。我从链接中检查了这段代码,它似乎不符合我的需要。要获取标记值,只需执行以下操作:string tag=(string)this.NavigationContext.QueryString[“id”];问题是我无法获取标记的值来发送它。它所在的地方是无法到达的。如果我能给textblock起个名字,然后用name.tag来获取值,那就太好了。我想我现在明白你的问题了。你可以这样做。在XAML中只需执行以下操作:
在代码后面您可以执行以下操作:
字符串uri=string.Format(“/Views/Event\u View/Event\u View.XAML?id={0}”,this.myTextBlock.Tag);NavigationService.Navigate(新Uri(Uri,UriKind.Relative))嘿,谢谢这看起来好像可以用。我现在正在测试它。
if (this.NavigationContext.QueryString.ContainsKey("ProductId"))
{
    productID = this.NavigationContext.QueryString["ProductId"];
}
else
{
    productID = App.Current.Resources["FeaturedProductID"].ToString();
}
private void StackPanel_Tap( object sender, GestureEventArgs e ) {
    int eventid = (( sender as StackPanel ).DataContext as MyObject).EventId_;

    string uri = String.Format("/Views/Event_View/Event_View.xaml?id={0}", eventid);
    NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}