Pratik Shirse

Pratik Shirse

  • 1.4k
  • 563
  • 38.1k

System.TypeInitializationException: GridView

Jun 29 2019 5:44 AM
we are create new New Project in vs2019 
xamarin.forms with Master Details(android & Ios) also creating the grid view  but when i run the project and click on the GridListPage we getting the error 
 
  
 
my code is below kindly suggest us where is the wrong 
 
GridListPage.xaml 
  1. <?xml version="1.0" encoding="utf-8" ?>    
  2. <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"    
  3.              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"    
  4.              x:Class="CollectionViewSample.Views.GridListPage"         
  5.              xmlns:vm="clr-namespace:CollectionViewSample.ViewModels"    
  6.              Title="{Binding Title}">    
  7.     
  8.     <ContentPage.BindingContext>    
  9.         <vm:GridListViewModel />    
  10.     </ContentPage.BindingContext>    
  11.     
  12.     <ContentPage.Content>    
  13.         <StackLayout>    
  14.             <CollectionView x:Name="CV" ItemsSource="{Binding DataSource}" VerticalOptions="Center" HorizontalOptions="Center" Margin="10,0,10,0">    
  15.                 <CollectionView.ItemsLayout>    
  16.                     <GridItemsLayout Orientation="Vertical" Span="2"/>    
  17.                 </CollectionView.ItemsLayout>    
  18.                 <CollectionView.ItemTemplate>    
  19.                     <DataTemplate x:DataType="vm:GridListViewModel">    
  20.                         <Frame BorderColor="LightGray" CornerRadius="3" HasShadow="False">    
  21.                             <Grid>    
  22.                                 <Grid.ColumnDefinitions>    
  23.                                     <ColumnDefinition Width="Auto"/>    
  24.                                     <ColumnDefinition Width="100" />    
  25.                                 </Grid.ColumnDefinitions>    
  26.                                 <Grid.RowDefinitions>    
  27.                                     <RowDefinition Height="Auto"/>    
  28.                                     <RowDefinition Height="*"/>    
  29.                                 </Grid.RowDefinitions>    
  30.                                 <Image Grid.Column="0" Source="person" Aspect="Fill"/>    
  31.                                 <StackLayout Grid.Column="1">    
  32.                                     <Label Text="{Binding}" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand"/>    
  33.                                 </StackLayout>    
  34.                             </Grid>    
  35.                         </Frame>    
  36.                     </DataTemplate>    
  37.                 </CollectionView.ItemTemplate>    
  38.             </CollectionView>    
  39.         </StackLayout>    
  40.     </ContentPage.Content>    
  41. </ContentPage>    
 
 GridListViewModel.cs
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4.   
  5. namespace CollectionViewSample.ViewModels  
  6. {  
  7.     public class GridListViewModel : BaseViewModel  
  8.     {  
  9.         public GridListViewModel()  
  10.         {  
  11.             Title = "Grid List View";  
  12.   
  13.         }  
  14.     }  
  15. }  
 
 GridListPage.xaml.cs
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. using Xamarin.Forms;  
  8. using Xamarin.Forms.Xaml;  
  9.   
  10. namespace CollectionViewSample.Views  
  11. {  
  12.     [XamlCompilation(XamlCompilationOptions.Compile)]  
  13.     public partial class GridListPage : ContentPage  
  14.     {  
  15.         public List<string> DataSource { get; }  
  16.   
  17.         public GridListPage()  
  18.         {  
  19.             InitializeComponent();  
  20.             DataSource = new List<string>  
  21.             {  
  22.                 "Alan",  
  23.                 "Betty",  
  24.                 "Charles",  
  25.                 "David",  
  26.                 "Edward",  
  27.                 "Francis",  
  28.                 "Gary",  
  29.                 "Helen",  
  30.                 "Ivan",  
  31.                 "Joel",  
  32.                 "Kelly",  
  33.                 "Larry",  
  34.                 "Mary",  
  35.                 "Nancy",  
  36.                 "Olivia",  
  37.                 "Peter",  
  38.                 "Quincy",  
  39.                 "Robert",  
  40.                 "Stephen",  
  41.                 "Timothy",  
  42.                 "Ursula",  
  43.                 "Vincent",  
  44.                 "William",  
  45.                 "Xavier",  
  46.                 "Yvonne",  
  47.                 "Zack"  
  48.             };  
  49.             CV.BindingContext = this;  
  50.         }  
  51.   
  52.     }  
  53. }  
 
 
 

Brought to you by: JavaScript SDK for Bold BI dashboard and analytics embedding. Free trial.

Answers (3)