/// <summary> /// Notes the grid view. /// </summary> /// <param name="list">The list.</param> public void NoteGridView(IList <Note> list) { /// adds two column for grid view gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(120) }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(120) }); gridLayout.Margin = 5; int rowCount = 0; /// depending upon number of notes it will create number of rows which will be divided in two columns for (int row = 0; row < list.Count; row++) { /// to create a one row for two notes if (row % 2 == 0) { /// create a row with height depends on note size gridLayout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Auto) }); rowCount++; } } //ListView listView = new ListView() { HasUnevenRows = true }; var productIndex = 0; var indexe = -1; /// Iterate a single row at a time to add two notes in one row for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { /// iterating column to add per note in each column in a single row for (int columnIndex = 0; columnIndex < 2; columnIndex++) { Note data = null; indexe++; /// to maintain the size of array to avoid exception if (indexe < list.Count) { data = list[indexe]; } /// Once every note is added in respective column and row than it will break if (productIndex >= list.Count) { break; } productIndex += 1; /// label for title var label = new Label { Text = data.Title, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, }; var labelKey = new Label { Text = data.Key, IsVisible = false }; /// label for content of the notes var Content = new Label { Text = data.Content, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, }; StackLayout layout = new StackLayout() { Spacing = 2, Margin = 2, BackgroundColor = Color.White }; var tapGestureRecognizer = new TapGestureRecognizer(); layout.Children.Add(labelKey); layout.Children.Add(label); layout.Children.Add(Content); layout.GestureRecognizers.Add(tapGestureRecognizer); /// adding StackLayout to frame to display it in card view var frame = new Frame(); frame.Content = layout; /// adding tap event tapGestureRecognizer.Tapped += (object sender, EventArgs args) => { StackLayout layout1 = (StackLayout)sender; IList <View> item = layout1.Children; Label keyValue = (Label)item[0]; var keyVal = keyValue.Text; Navigation.PushAsync(new UpdateNote(keyVal)); }; gridLayout.Children.Add(frame, columnIndex, rowIndex); } } }
public void NoteListView(IList <Note> list) { gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(280) }); gridLayout.Margin = 5; int rowCount = list.Count; //ListView listView = new ListView() { HasUnevenRows = true }; var productIndex = 0; var title = ""; var content = ""; var indexe = -1; /// Iterate a single row at a time to add two notes in one row for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { /// iterating column to add per note in each column in a single row for (int columnIndex = 0; columnIndex < 1; columnIndex++) { Note data = null; indexe++; /// to maintain the size of array to avoid exception if (indexe < list.Count) { data = list[indexe]; } /// Once every note is added in respective column and row than it will break if (productIndex >= list.Count) { break; } productIndex += 1; var index = rowIndex * columnIndex + columnIndex; title = data.Title; content = data.Content; var layout = new StackLayout(); /// label for title var label = new Label { Text = title, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, }; /// label for content of the notes var Content = new Label { Text = content, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Start, }; layout.Children.Add(label); layout.Children.Add(Content); layout.Spacing = 2; layout.Margin = 2; layout.BackgroundColor = Color.White; /// adding StackLayout to frame to display it in card view var frame = new Frame(); frame.Content = layout; gridLayout.Children.Add(frame, columnIndex, rowIndex); } } }