我可以使TextBlock可单击 - 基于XML解析结果吗?

时间:2011-08-19 22:39:32

标签: xml silverlight linq windows-phone-7

我有一个包含多个文本块的堆栈面板,这些文本块绑定到XML文件的解析结果。

我想要的是让每个结果都有一个onlick事件,然后链接到更多信息甚至是message.show框,但它必须使用它显示的结果中的值。

这是列表框的.Xaml部分,它消除了结果。)

<ListBox Height="435"
         HorizontalAlignment="Left"
         Name="TradeSearch1"
         VerticalAlignment="Top"
         Width="397"
         Grid.ColumnSpan="3"
         Margin="0,63,0,0">
<ListBox.ItemTemplate>
    <DataTemplate>
        <StackPanel Orientation="Horizontal"
                    Height="200">
            <Image Source="{Binding ImageSource}"
                   Height="150" Width="150"
                   VerticalAlignment="Top"
                   Margin="0,10,8,0"/>
            <StackPanel Width="370" >
                <TextBlock Text="{Binding Title}"
                           TextWrapping="Wrap"
                           Foreground="#FFE51A1A"
                           FontSize="16" />
                <TextBlock Text="{Binding PriceDisplay}" 
                           TextWrapping="Wrap" 
                           FontSize="20" 
                           Foreground="Black" />
                <TextBlock Text="{Binding ListingId}" 
                           TextWrapping="Wrap" 
                           FontSize="20" 
                           Foreground="Black" />
                <TextBlock Text="{Binding Region}" 
                           TextWrapping="Wrap" 
                           FontSize="18" 
                           Foreground="Black" />
            </StackPanel>
        </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>

其中一个文本块返回(ListingID)的值。理想情况下,当用户点击此结果时,他们将被带到另一个页面,这将基于所产生的LIstingID表单产生更多结果。

列表ID为400332970

有没有办法将这个值传递到另一个页面并在这样的东西中使用它?其中ListingID.XMl将是onClick结果中的listingId。

WebClient Trademe = new WebClient();
Trademe.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Trademe_DownloadStringCompleted);
Trademe.DownloadStringAsync(new Uri("http://api.trademe.co.nz/v1/Listings/" + ListingID.xml));

如果这令人困惑,我很抱歉,我尽力解释。希望有人知道我在说什么。

1 个答案:

答案 0 :(得分:2)

如果我理解正确,您可以使用QueryString将信息传递到下一页。

//handle the selectionchanged event (replace 'myObject' with your object type)
void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
{
    var lbi = ((sender as ListBox).SelectedItem as myObject);
    if(lbi != null)
    {
        string id = lbi.ListingId.ToString();
        NavigationService.Navigate("/NewPage.xaml?listingid=" + id, UriKind.Relative));    
    }
}

然后,在NewPage.xaml页面中,您可以读取查询字符串的值。 (您可以添加错误检查,或使用QueryString.TryGetValue来避免异常)。

string id = NavigationContext.QueryString["listingid"];

您可以使用id作为发布的下载代码的一部分。