2017-06-08 119 views
0

我設置了ListView的ItemSource,並嘗試在ListView DataTemplate中根據該特定項目的屬性的子項創建多個標籤(項目是演出,並且他們有一個樂隊列表成員,並試圖列出樂隊成員)。訪問ListView項目數據

我不知道如何獲得當前項目的屬性,它有創建模板,有人可以幫忙嗎?

  ListView listView = new ListView { 
      ItemsSource = viewModel.gigs, 
       ItemTemplate = new DataTemplate (() => { 

        var grid = new Grid(); 
      grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star)}); 

        for(int x = 0;x<=viewModel.bandMembers.Count;x++) { 
         grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)}); 
        } 

        var venueName = new Label { Text = "Top Left" }; 
        venueName.SetBinding (Label.TextProperty, "Venue"); 
        grid.Children.Add(venueName, 0, 0); 

        for(int x = 0;x<THISITEM.bandMembers.Count;x++) { 
         grid.Children.Add(new Label() {Text="Test"},x,0); 
        } 

     return new ViewCell { View = grid }; 

      }); 

      // Build the page. 
      this.Content = new StackLayout { 
       Children = { 
        header, 
        listView 
       } 
      }; 

回答

0

您可以覆蓋ViewCell OnBindingContextChnaged功能,從BindingContext中

+0

得到的ItemData這是我落得這樣做。不優雅,但做的工作。 –