Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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# LINQ到XML解析多个Uri';s到单个超链接按钮_C#_Windows Phone 7.1_Windows Phone 7 - Fatal编程技术网

C# LINQ到XML解析多个Uri';s到单个超链接按钮

C# LINQ到XML解析多个Uri';s到单个超链接按钮,c#,windows-phone-7.1,windows-phone-7,C#,Windows Phone 7.1,Windows Phone 7,我在将解析的字符串传递给按钮单击事件时遇到问题。这个问题在这个线程中得到了解决,但现在还有另一个小问题,就是LINQ到XML。我正在制作一个页面,该页面将显示我制作的所有应用程序,并将使用我将在服务器上托管的XML进行更新。在那个页面上,我正在解析应用程序的图标、标题、价格和市场Uri。我将应用程序的Uri和标题绑定到一个hyperlinkbutton,但问题是列表中的每个hyperlinkbutton都会将我带到同一个市场页面。如何修复它,使每个超链接按钮都能导航到不同的页面 代码如下:

我在将解析的字符串传递给按钮单击事件时遇到问题。这个问题在这个线程中得到了解决,但现在还有另一个小问题,就是LINQ到XML。我正在制作一个页面,该页面将显示我制作的所有应用程序,并将使用我将在服务器上托管的XML进行更新。在那个页面上,我正在解析应用程序的图标、标题、价格和市场Uri。我将应用程序的Uri和标题绑定到一个hyperlinkbutton,但问题是列表中的每个hyperlinkbutton都会将我带到同一个市场页面。如何修复它,使每个超链接按钮都能导航到不同的页面

代码如下:

  public partial class MorePage : PhoneApplicationPage
{
    private string appLink;

    public MorePage()
    {
        InitializeComponent();
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        WebClient client = new WebClient();
        Uri uritoXML = new Uri("http://www.allanhaapalainen.com/AppsXML/MorePageXML.xml", UriKind.RelativeOrAbsolute);
        client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
        client.DownloadStringAsync(uritoXML);

        base.OnNavigatedTo(e);
    }

 public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
    {
        XDocument moreApps = XDocument.Parse(e.Result);

        morePageAppList.ItemsSource = from Apps in moreApps.Descendants("App")
                                       select new MoreApps
                                       {
                                           MoreImage = Apps.Element("link").Value,
                                           Price = Apps.Element("price").Value,
                                           Title = Apps.Element("title").Value
                                       };

        var attribute = (from Apps in moreApps.Descendants("App")
                         select new MoreApps
                         {
                             AppAttribute = (string)Apps.Attribute("id").Value
                         }).FirstOrDefault();


        string appAttr = attribute.AppAttribute;

        var link = (from Apps in moreApps.Descendants("App")
                    where Apps.Attribute("id").Value == appAttr
                    select new MoreApps
                    {
                        AppUri = (string)Apps.Element("marketplace").Value
                    }).FirstOrDefault();

        appLink = link.AppUri;            
    }

    private void App_Name_Click(object sender, RoutedEventArgs e)
    {
        ShowMarket(appLink);
    }

    private void ShowMarket(string id)
    {
        MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask();
        marketplaceDetailTask.ContentIdentifier = id;
        marketplaceDetailTask.Show();
    }

}
以及XAML:

<ListBox Height="500" Width="Auto" Name="morePageAppList" Margin="0,0,0,0" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                        <StackPanel Orientation="Horizontal" Height="173">
                            <Image Source="{Binding MoreImage}" Height="Auto" Width="Auto" />
                                <StackPanel Orientation="Vertical">
                                     <HyperlinkButton Name="appName" Content="{Binding Title}" Margin="15,60,0,0"  Click="App_Name_Click" />
                                     <TextBlock Name="price" Text="{Binding Price}" Margin="28,0,0,0" Foreground="#FFBD0000" />
                                </StackPanel>
                        </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

正如我在上一篇文章中提到的,您可以使用tag参数。更新您的数据模板

<DataTemplate>
                        <StackPanel Orientation="Horizontal" Height="173">
                            <Image Source="{Binding MoreImage}" Height="Auto" Width="Auto" />
                                <StackPanel Orientation="Vertical">
                                     <HyperlinkButton Name="appName" Content="{Binding Title}" Tag="{Binding}" Margin="15,60,0,0"  Click="App_Name_Click" />
                                     <TextBlock Name="price" Text="{Binding Price}" Margin="28,0,0,0" Foreground="#FFBD0000" />
                                </StackPanel>
                        </StackPanel>
                </DataTemplate>

Show the XAML for morePageAppListabove是列表框的XAML它似乎正在工作,但模拟器给出了一个市场错误。它显示的页面刚刚好之前。奇怪的我想,它可能会在真手机上工作。再次感谢你帮了我的忙!
private void App_Name_Click(object sender, RoutedEventArgs e)
    {
        var button = (HyperLinkButton)sender;
        var selectedApp = (MoreApps)button.Tag;

        ShowMarket(selectedApp.AppUri);
    }