private void UpdateGearItemGrid(GearItemGrid gearItemGrid, CharacterSheet.GearItem item, int itemIndex)
        {
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return;
            }
            MainPage.SetTapHandler(gearItemGrid.grid, (s, e) => GearItem_DoubleTap(item), 2);
#if EXPAND_SELECTED
            if (gearItemGrid.selectedHandler != null)
            {
                gearItemGrid.selected.CheckedChanged -= gearItemGrid.selectedHandler;
            }
            gearItemGrid.selectedHandler          = (s, e) => GearItem_CheckedChanged(item, e.Value);
            gearItemGrid.selected.IsChecked       = item.selected;
            gearItemGrid.selected.CheckedChanged += gearItemGrid.selectedHandler;
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(gearItemGrid.grid, (s, e) => GearItem_Tap(gearItemGrid.selected), 1);
#endif
#endif
            gearItemGrid.name.Text = item.AsString(sheet);
            if (gearItemGrid.viewButtonHandler != null)
            {
                gearItemGrid.viewButton.Clicked -= gearItemGrid.viewButtonHandler;
            }
            gearItemGrid.viewButtonHandler   = (s, e) => GearItemViewButton_Tap(item);
            gearItemGrid.viewButton.Clicked += gearItemGrid.viewButtonHandler;
            gearItemGrid.name.FontAttributes = item.active ? FontAttributes.Bold : FontAttributes.None;
        }
        private void RemoveGearItemGrid(GearItemGrid gearItemGrid)
        {
            if (gearItemGrid == null)
            {
                return;
            }
#if EXPAND_SELECTED
            var sgig = gearItemGrid as SelectedGearItemGrid;
            if (sgig != null)
            {
                RemoveGearItemGrid(sgig);
                return;
            }
#endif
            Gear.Children.Remove(gearItemGrid.grid);
            gearItemGrids.Remove(gearItemGrid);
            gearItemGridsPool.Add(gearItemGrid);
        }
        private GearItemGrid CreateGearItemGrid(CharacterSheet.GearItem item, int itemIndex)
        {
            if (item == null)
            {
                return(null);
            }
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return(null);
            }
            if (gearItemGridsPool.Count > 0)
            {
                var gearItemGrid = gearItemGridsPool[0];
                gearItemGridsPool.RemoveAt(0);
                UpdateGearItemGrid(gearItemGrid, item, itemIndex);
                return(gearItemGrid);
            }
            var grid = new Grid()
            {
                ColumnSpacing   = 5,
                RowSpacing      = 5,
                BackgroundColor = Color.LightGray,
            };

            grid.ColumnDefinitions = new ColumnDefinitionCollection()
            {
#if EXPAND_SELECTED
                new ColumnDefinition()
                {
                    Width = GridLength.Auto
                },
#endif
                new ColumnDefinition()
                {
                    Width = GridLength.Star
                },
                new ColumnDefinition()
                {
                    Width = GridLength.Auto
                },
            };
            grid.RowDefinitions = new RowDefinitionCollection()
            {
                new RowDefinition()
                {
                    Height = GridLength.Auto
                },
            };
            MainPage.AddTapHandler(grid, (s, e) => GearItem_DoubleTap(item), 2);
#if EXPAND_SELECTED
            var selectedcb = new CheckBox()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                IsChecked         = item.selected,
            };
            EventHandler <CheckedChangedEventArgs> selectedHandler = (s, e) => GearItem_CheckedChanged(item, e.Value);
            selectedcb.CheckedChanged += selectedHandler;
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(grid, (s, e) => GearItem_Tap(selectedcb), 1);
#endif
#endif
            var gearItemNameFrame = CreateFrame(item.AsString(sheet));
            var gearItemName      = gearItemNameFrame.Content as Label;
            gearItemName.FontAttributes = item.active ? FontAttributes.Bold : FontAttributes.None;
            var viewButton = new Button()
            {
                Text              = "View",
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Button)),
                TextColor         = Color.Black,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
            };
            EventHandler viewButtonHandler = (s, e) => GearItemViewButton_Tap(item);
            viewButton.Clicked += viewButtonHandler;
            var column = 0;
#if EXPAND_SELECTED
            grid.Children.Add(selectedcb, column++, 0);
#endif
            grid.Children.Add(gearItemNameFrame, column++, 0);
            grid.Children.Add(viewButton, column++, 0);
            var newGearItemGrid = new GearItemGrid()
            {
                grid = grid,
#if EXPAND_SELECTED
                selectedHandler = selectedHandler,
                selected        = selectedcb,
#endif
                name              = gearItemName,
                viewButton        = viewButton,
                viewButtonHandler = viewButtonHandler,
            };

            return(newGearItemGrid);
        }
 private void UpdateGearItemGrid(GearItemGrid gearItemGrid, KeyValuePair <CharacterSheet.GearItem, int> kvp)
 {
     UpdateGearItemGrid(gearItemGrid, kvp.Key, kvp.Value);
 }