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 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);
        }
        public void UpdateView()
        {
            pushedPage = null;
            if (sheet == null)
            {
                return;
            }
            UpdateValue();
            if (modifier == null)
            {
                return;
            }

            CharacterSheet.GearItem item = null;
            if (modifier.sourceItemUID == CharacterSheet.InvalidUID)
            {
                LinkedItem.Text = string.Empty;
            }
            else
            {
                item = sheet.GetItemByUID(modifier.sourceItemUID);
                if (item != null)
                {
                    LinkedItem.Text           = item.AsString(sheet);
                    LinkedItem.FontAttributes = item.active ? FontAttributes.Bold : FontAttributes.None;
                    LinkedItem.TextColor      = (item.active || !modifier.mustBeActive) ? Color.Green : Color.Red;
                }
                else
                {
                    LinkedItem.Text      = "Item not found";
                    LinkedItem.TextColor = Color.Red;
                }
            }
            MainPage.SetTapHandler(LinkedItemFrame, (s, e) => SelectItem(item));
            var loc = sheet.GetLevelOfClass(modifier.className);

            if (!modifier.multiplyToLevel)
            {
                ClassName.Text = string.Empty;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(modifier.className) || (loc != null))
                {
                    ClassName.Text      = loc == null ? "Total Level" : modifier.className;
                    ClassName.TextColor = Color.Green;
                }
                else
                {
                    ClassName.Text      = "Class \"" + modifier.className + "\" not found";
                    ClassName.TextColor = Color.Red;
                }
            }

            var lms = loc == null ? "Total Level" : "Level Of " + modifier.className;
            var lm  = modifier.levelMultiplier.AsString(lms);

            if (lm == lms)
            {
                lm = string.Empty;
            }
            LevelMultiplier.Text = !modifier.multiplyToLevel ? string.Empty : lm;
            LevelMultiplierFrame.BackgroundColor  = modifier.multiplyToLevel ? Color.White : Color.LightGray;
            LevelMultiplierFrame.InputTransparent = !modifier.multiplyToLevel;

            MainPage.SetTapHandler(ClassNameFrame, (s, e) => SelectClass(modifier.className));
            AutoNaming.IsChecked = modifier.autoNaming;
        }