2016-07-01 8 views
1

私はウェブサービスから私のclubidの値を取得し、次のページに渡したいので、私は動的なクラブの詳細を持っています。しかし、私はそれをしようとしたとき、それは私にいくつかのエラーを示しています。これは私のコードです。リスト内のすべての項目は、 "LBID" という名前のLabelを持っているので、名前を使用してListviewから値を取得する方法Xamarin.form

ListClubs.xaml.cs

ClubApiClient service = new ClubApiClient(); 

public ListClubs() 
{ 
    InitializeComponent(); 
} 

protected async override void OnAppearing() 
{ 
    base.OnAppearing(); 
    await setClubs(Clublistview); 
} 

private async Task setClubs(ListView listview) 
{ 
    var clublist = await service.getClubList(2); 
    listview.ItemsSource = clublist.ToList(); 
} 

async void OnListClubsClicked(object sender, EventArgs e) 
{ 
    int clubid = int.Parse(lbId.Text); //Error msg: The name 'lbId' does not exist in the context 
    await Navigation.PushAsync(new DetailedClub()); 
} 

ListClubs.xaml

<ListView x:Name="Clublistview"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout BackgroundColor="White" 
        Orientation="Vertical"> 
         <StackLayout Orientation="Horizontal"> 
          <Image Source="{Binding Logo}" IsVisible="true" WidthRequest="42" HeightRequest="42"/> 
          <Button Text="{Binding Name}" x:Name="BtnClub" AbsoluteLayout.LayoutBounds="100, 25, 100, 25" Clicked="OnListClubsClicked" TextColor="Black" VerticalOptions="FillAndExpand"/> 
          <Label Text="{Binding Id}" x:Name="lbId" IsVisible="false"/> 
         </StackLayout> 
        </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 

答えて

2

"LBIDは" 有用ではありません。

あなたのButton

<Button Text="{Binding Name}" x:Name="BtnClub" AbsoluteLayout.LayoutBounds="100, 25, 100, 25" Clicked="OnListClubsClicked" TextColor="Black" VerticalOptions="FillAndExpand" CommandParameter="{Binding Id}" /> 

async void OnListClubsClicked(object sender, EventArgs e) 
{ 
    Button btn = (Button) sender; 
    int clubid = (int) btn.CommandParameter; 
    // pass the clubid to your Detail page 
    await Navigation.PushAsync(new DetailedClub(clubid)); 
} 
+0

おかげで男にIDを追加するためにCommandParameterを使用することができます!それは今働く:) –

関連する問題