I am Trying to Write My listView (with multiple Binding Objects in it and user Entrys as input) to a Text file. I came up with the Idea of Serialize it to Json and then write it to text with button clicked (I am new here :)). But I get stocked in Json Loops errors.
The name of my listView is LL:
private void Save_Clicked(object sender, EventArgs e)
{
string Listi = JsonConvert.SerializeObject(LL);
File.WriteAllText(DailyTex, Listi);
editor.Text = File.ReadAllText(DailyTex);
DisplayAlert("Save completed", "Please Try Egain", "Continue");
}
The error is:
Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'ParentView' with type 'Xamarin.Forms.Grid'. Path 'TemplatedItems[0].View.Children[0]'.'
My Xamlpage
<ListView x:Name="LL" Grid.Row="3" ItemsSource="{Binding energy}" HeightRequest="300" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5" BackgroundColor="White" RowSpacing="40" >
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="label" HorizontalOptions="Center" Text="{Binding EE}" FontSize="18" TextColor="Black" Grid.Column="0" Grid.Row="0" />
<Entry TextChanged="Entry_TextChanged" HorizontalOptions="Center" VerticalOptions="Center" Keyboard="Numeric" Placeholder=". . . . . . . ." Grid.Column="1" Grid.Row="0" BackgroundColor="Beige" WidthRequest="80" />
<Entry TextChanged="Entry_TextChanged_1" HorizontalOptions="Center" VerticalOptions="Center" Keyboard="Numeric" Placeholder=". . . . . . . ." Grid.Column="2" Grid.Row="0" BackgroundColor="Beige" WidthRequest="80"/>
<Entry TextChanged="Entry_TextChanged_2" HorizontalOptions="Center" VerticalOptions="Center" Keyboard="Numeric" Placeholder=". . . . . . . ." Grid.Column="3" Grid.Row="0" BackgroundColor="Beige" WidthRequest="80"/>
<BoxView Grid.Column="0" Grid.Row="0" BackgroundColor="Black" WidthRequest="1" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
<BoxView Grid.Column="1" Grid.Row="0" BackgroundColor="Black" WidthRequest="1" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
<BoxView Grid.Column="2" Grid.Row="0" BackgroundColor="Black" WidthRequest="1" HorizontalOptions="EndAndExpand" VerticalOptions="FillAndExpand"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>