2012-01-06 7 views
0

ボタンのクリックイベントに解析された文字列を渡すことに問題がありました。このスレッドhereで解決されましたが、もう少し小さな問題がありますが、それはLINQ TO XMLです。私が作るすべてのアプリケーションを表示するページを作っています。私のサーバー上でホストするXMLで更新されます。そのページでは、アイコン、タイトル、価格、アプリのマーケットプレイスUriを解析しています。私はUriとアプリケーションのタイトルを単一のハイパーリンクボタンにバインドしていますが、問題は、リストのすべてのハイパーリンクボタンが私を同じマーケットプレイスページに連れて行くことです。すべてのハイパーリンクボタンが別のページに移動するように、どうすれば修正できますか?ここで複数のUriを単一のハイパーリンクボタンにパースするLINQ to XML

はコードです:

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> 
+0

は、上記morePageAppList –

+0

ためのXAMLは、それが動作しているようだが、エミュレータは、市場のエラーを与え、リストボックス –

答えて

1

私はあなたの以前の記事で述べたように、あなたがタグのパラメータを使用することができます。あなたのDataTemplate

<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> 

は、あなたのイベントに

private void App_Name_Click(object sender, RoutedEventArgs e) 
    { 
     var button = (HyperLinkButton)sender; 
     var selectedApp = (MoreApps)button.Tag; 

     ShowMarket(selectedApp.AppUri); 
    } 
+1

のXAMLで表示します更新します。以前はページがきれいだった。奇妙な。それはおそらく実際の電話で動作するでしょう。私を助けてくれてありがとう! –