Why my app crash after scrolling ListView with SubItems

XAML CODE:



<ListView.Header>

<Grid.ColumnDefinitions>


</Grid.ColumnDefinitions>
<Grid.RowDefinitions>



</Grid.RowDefinitions>

                <Image Source="icon.png"
                       Grid.Column="0" VerticalOptions="FillAndExpand"
                       Grid.Row="1"/>
                <Label Grid.Column="1" Grid.Row="1" TextColor="White"
                       x:Name="lblUser" FontSize="26" FontAttributes="Bold"
                       Text="Usurio" VerticalOptions="Start"/>
                <Label Grid.Column="1" Grid.Row="1" TextColor="White"
                       FontSize="16" Text="[email protected]"
                       VerticalOptions="End"/>
            </Grid>
        </ListView.Header>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Padding="15,10" HorizontalOptions="FillAndExpand">
                        <ListView x:Name="ItemsListView"
                                  SeparatorVisibility="None"
                                  HasUnevenRows="true"
                                  ItemsSource="{Binding Items}">
                            <ListView.Header>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="40"/>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="40"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="40"/>
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding ImageHeader}"
                                           Grid.Column="0" Grid.Row="0"/>
                                    <Label VerticalOptions="FillAndExpand" 
                                           VerticalTextAlignment="Center" 
                                           Text="{Binding TitleHeader}"
                                           FontSize="24"
                                           Grid.Column="1" Grid.Row="0"/>
                                    <Image Source="ic_arrow_down.png"
                                           Grid.Column="2" Grid.Row="0"/>
                                </Grid>
                            </ListView.Header>
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <ViewCell>
                                        <StackLayout Margin="20,0,0,0">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="40"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="40"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="40"/>
                                                </Grid.RowDefinitions>
                                                <Image Source="{Binding Image}"
                                                       Grid.Column="0" Grid.Row="0"/>
                                                <Label VerticalOptions="FillAndExpand" 
                                                       VerticalTextAlignment="Center" 
                                                       Text="{Binding Title}"
                                                       FontSize="18"
                                                       Grid.Column="1" Grid.Row="0"/>
                                                <Image Source="ic_arrow_down.png"
                                                       Grid.Column="2" Grid.Row="0"/>
                                            </Grid>
                                        </StackLayout>
                                    </ViewCell>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

CS CODE:

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class HomeMaster : ContentPage
{
public ListView ListView;

    public HomeMaster()
    {
        InitializeComponent();

        BindingContext = new HomeMasterViewModel();
        ListView = MenuItemsListView;
    }

    class HomeMasterViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<HomeMenuItem> MenuItems { get; set; }

        public HomeMasterViewModel()
        {
            MenuItems = new ObservableCollection<HomeMenuItem>(new[]
            {
                new HomeMenuItem ("Page 1", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),
                new HomeMenuItem ("Page 2", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),
                new HomeMenuItem ("Page 3", "ic_monetization.png",new ObservableCollection<Item> {
                    new Item("Item 1", "ic_help.png", null), new Item("Item 2", "ic_help.png", null)} ),

            });
        }

        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}

Answers

Sign In or Register to comment.