C# 使用REST使用web api

C# 使用REST使用web api,c#,xaml,C#,Xaml,我正在开发一个使用ASP.NET服务的Windows 8.1应用程序 我想按id显示俱乐部(管理俱乐部的应用程序)。在我的欢迎页面中,我有一个俱乐部(徽标)列表,当我点击一个徽标时,我想显示有关俱乐部的所有信息。(让一切顺利进行) 这是我的方法 private Club GetClubById(int id) { HttpClient httpClient = new HttpClient(); string result = httpClient.GetStringAsyn

我正在开发一个使用ASP.NET服务的Windows 8.1应用程序

我想按id显示俱乐部(管理俱乐部的应用程序)。在我的欢迎页面中,我有一个俱乐部(徽标)列表,当我点击一个徽标时,我想显示有关俱乐部的所有信息。(让一切顺利进行)

这是我的方法

private Club GetClubById(int id) 
{ 
    HttpClient httpClient = new HttpClient();
    string result = httpClient.GetStringAsync("http://xxxxxx:2209/api/clubapi/" + id).Result;
    Club club = JsonConvert.DeserializeObject<Club>(result);
    return club; 
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    navigationHelper.OnNavigatedTo(e);

    DefaultViewModel["ClubById"] = GetClubById(1003);
   //this ID already exists I don t know how to bind the id with the xaml.
}
这是我在XAML中的GridView:

<HubSection Width="500" Header="Clubs">

            <DataTemplate>
                <GridView ItemsSource="{Binding ListClubs}" SelectionMode="None" Tapped="GridView_Tapped"  >


                    <GridView.ItemTemplate>

                        <DataTemplate>
                            <Grid>
 <Image Source="{Binding Logo,Converter={StaticResource bytesToImageSourceConverter}}" Height="100" Width="200" Stretch="UniformToFill"/>
                                <TextBlock  TextWrapping="NoWrap" Width="100"  >
          <Run Text="{Binding ClubName}" Foreground="Black"  > </Run>
                                </TextBlock>

                            </Grid>
                        </DataTemplate>
                      </GridView.ItemTemplate>
                 </GridView>
            </DataTemplate>
        </HubSection>


看起来您需要将俱乐部ID绑定到数据模板中的隐藏元素,并访问OnNavigatedTo事件中的数据。我已经修复了,谢谢
<HubSection Width="500" Header="Clubs">

            <DataTemplate>
                <GridView ItemsSource="{Binding ListClubs}" SelectionMode="None" Tapped="GridView_Tapped"  >


                    <GridView.ItemTemplate>

                        <DataTemplate>
                            <Grid>
 <Image Source="{Binding Logo,Converter={StaticResource bytesToImageSourceConverter}}" Height="100" Width="200" Stretch="UniformToFill"/>
                                <TextBlock  TextWrapping="NoWrap" Width="100"  >
          <Run Text="{Binding ClubName}" Foreground="Black"  > </Run>
                                </TextBlock>

                            </Grid>
                        </DataTemplate>
                      </GridView.ItemTemplate>
                 </GridView>
            </DataTemplate>
        </HubSection>