Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

C# Xamarin Forms Items not set in a Grouped ListView

$
0
0

I am trying to set the ItemsSource of a ListView from a nested ObservableCollection List. While HeaderGroups are being created, Items in the groups are empty. Any idea? Here is my code:
`public class TableDataGroup
{
public TableDataGroup(String imagepath, String championship, String tip)//, Color headergroupbgcolor,)
{
this.ImagePath = imagepath;
this.Championship = championship;
this.Tip = tip;
this.Items = new ObservableCollection();
}

    public string ImagePath { get; private set; }
    public string Championship { get; private set; }
    public string Tip { get; private set; }

    public ObservableCollection<TableDataItem> Items { get; set; }
}

public class TableDataItem
{
    public TableDataItem(String imagepath, Color backgroundTipColour, String time, String teamone...)
    {
        this.ImagePath = imagepath;
        this.BackgroundTipColour = backgroundTipColour;
        this.Time = time;
        this.TeamOne = teamone;
        //...
    }

    public string ImagePath { get; private set; }
    public Color BackgroundTipColour { get; private set; }
    public string Time { get; private set; }
    public string TeamOne { get; private set; }
    //...
}`

Calls:
mainPageLoadViewModel.tableDataGroup = new ObservableCollection<TableDataGroup>(); for (int i = 0; i < 10; i++) { TableDataGroup tableDataGroup = new TableDataGroup("value", "value", "value","TIP"); for (int x = 0; x < 10; x++) { tableDataGroup.Items.Add(new TableDataItem("flag", backgroundtipcolor, time, teamone, //...)); } mainPageLoadViewModel.tableDataGroup.Add(tableDataGroup); } ItemsCollectionView.ItemsSource = mainPageLoadViewModel.tableDataGroup;

xaml:
`
<ListView.GroupHeaderTemplate>


<ViewCell.View>





    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <Grid Padding="10,5,5,10" BackgroundColor="Gray">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="25" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="35"/>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="120"/>
                            <ColumnDefinition Width="45"/>
                        </Grid.ColumnDefinitions>
                        <Label Text="{Binding Time}" Grid.Column="0" FontSize="13" TextColor="Black" VerticalTextAlignment="Center" HorizontalOptions="StartAndExpand"></Label>
                        <Label Text="{Binding TeamOne}" FontSize="13" TextColor="Black" Grid.Column="1" VerticalTextAlignment="Center" HorizontalOptions="End"></Label>
                        <Label Text="{Binding ScoreTeamOne}" FontSize="13" Grid.Column="2" BackgroundColor="Gray" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" WidthRequest="25" MinimumWidthRequest="25"></Label>
                        <Label Text="{Binding ScoreTeamTwo}" FontSize="13" Grid.Column="3" BackgroundColor="Gray" TextColor="White" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" WidthRequest="25" MinimumWidthRequest="25"></Label>
                        <Label Text="{Binding TeamTwo}" FontSize="13" TextColor="Black" Grid.Column="4" VerticalTextAlignment="Center"></Label>
                        <Label Text="{Binding Tip}" FontSize="13" TextColor="White" Grid.Column="5" BackgroundColor="DarkSlateGray" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" HorizontalOptions="Fill"></Label>
                    </Grid>
                </ViewCell.View>
            </ViewCell>
            <!--<TextCell Text="{Binding Name}" Detail="{Binding Description}"></TextCell>-->
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>`

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>