public RestaurantMenuItemSubModifierPage(RestaurantMenuItemModifierPage restaurantMenuItemModifierPage, ModifierItemViewModel modifierItemView)
        {
            ModifierItemView = modifierItemView;

            InitializeComponent();

            NavigationPage.SetBackButtonTitle(this, AppResources.Back);
            var subMenuModifierItemViewsSource = new List <SubMenuModifierItemViewModel>();

            foreach (var subMenuModifierGroup in modifierItemView.MenuModifierVM.SubMenuModifierGroups)
            {
                subMenuModifierItemViewsSource.Add(new SubMenuModifierItemViewModel(modifierItemView, subMenuModifierGroup));
                var subMenuModifierItemViews = modifierItemView.MenuModifierVM.SubMenuModifiers
                                               .Where((t) => subMenuModifierGroup.ModifierIDs.Contains(t.MenuModifier.ID))
                                               .Select(t => new SubMenuModifierItemViewModel(modifierItemView, subMenuModifierGroup, t)).ToList();
                subMenuModifierItemViewsSource.AddRange(subMenuModifierItemViews);
                SubMenuModifierItemViews.AddRange(subMenuModifierItemViews);
            }

            ModifierItemView.SubMenuModifierItemViews = SubMenuModifierItemViews;
            foreach (var subMenuModifierItemView in SubMenuModifierItemViews)
            {
                var subMenuModifierItemViews = SubMenuModifierItemViews
                                               .Where((t) => subMenuModifierItemView.SubMenuModifierGroup.ModifierIDs.Contains(t.SubMenuModifierVM.MenuModifier.ID))
                                               .ToList();

                subMenuModifierItemView.PropertyChanged += (sender, e) =>
                {
                    if (e.PropertyName == nameof(subMenuModifierItemView.Quantity))
                    {
                        Price = restaurantMenuItemModifierPage.UpdatePriceUnSave(ModifierItemView);
                        foreach (var modifierItemViewGroup in subMenuModifierItemViews)
                        {
                            modifierItemViewGroup.RefreshEnabled();
                        }
                        Task.Run(() =>
                        {
                            new System.Threading.ManualResetEvent(false).WaitOne(100);
                        }).ContinueWith((s) =>
                        {
                            var itemsSelected = subMenuModifierItemViews.Where(t => t.IsSelected).ToList();
                            var countSelected = itemsSelected.Sum(t => t.Quantity);
                            var maxApplied    = subMenuModifierItemView.SubMenuModifierGroup.MaxApplied;
                            if (maxApplied < countSelected && subMenuModifierItemView.Quantity != subMenuModifierItemView.QuantityPrevious)
                            {
                                subMenuModifierItemView.Quantity = subMenuModifierItemView.QuantityPrevious;
                            }
                        }, TaskScheduler.FromCurrentSynchronizationContext());
                    }
                    if (!IsModifierItemViewChanging && e.PropertyName == nameof(subMenuModifierItemView.IsSelected))
                    {
                        IsModifierItemViewChanging = true;
                        var minApplied = subMenuModifierItemView.SubMenuModifierGroup.MinApplied;
                        var maxApplied = subMenuModifierItemView.SubMenuModifierGroup.MaxApplied;
                        if (minApplied == 1 && subMenuModifierItemViews.Where(t => t.IsSelected).LongCount() == 0)
                        {
                            subMenuModifierItemView.IsSelected = (true);
                        }
                        if (subMenuModifierItemView.IsSelected)
                        {
                            if (maxApplied == 1)
                            {
                                foreach (var modifierItemViewGroup in subMenuModifierItemViews)
                                {
                                    modifierItemViewGroup.IsSelected = (modifierItemViewGroup == subMenuModifierItemView);
                                }
                            }
                        }
                        foreach (var modifierItemViewGroup in subMenuModifierItemViews)
                        {
                            modifierItemViewGroup.RefreshEnabled();
                        }

                        Price = restaurantMenuItemModifierPage.UpdatePriceUnSave(ModifierItemView);

                        IsModifierItemViewChanging = false;
                    }
                };
            }

            ListViewSubModifiers.ItemsSource = subMenuModifierItemViewsSource;
            ListViewSubModifiers.ItemTapped += (sender, e) =>
            {
                if (e.Item != null)
                {
                    ListViewSubModifiers.SelectedItem = null;
                    SubMenuModifierItemViewModel subMenuModifierItemView = e.Item as SubMenuModifierItemViewModel;
                    if (subMenuModifierItemView.IsEnabled)
                    {
                        subMenuModifierItemView.IsSelected = !subMenuModifierItemView.IsSelected;
                    }
                }
            };

            Price = restaurantMenuItemModifierPage.UpdatePriceUnSave(ModifierItemView);

            ButtonDone.Clicked += async(sender, e) =>
            {
                string error = string.Empty;

                foreach (var subMenuModifierGroup in ModifierItemView.MenuModifierVM.SubMenuModifierGroups)
                {
                    var minApplied    = subMenuModifierGroup.MinApplied;
                    var itemsSelected = SubMenuModifierItemViews
                                        .Where((t) => subMenuModifierGroup.ModifierIDs.Contains(t.SubMenuModifierVM.MenuModifier.ID))
                                        .Where(s => s.IsSelected).ToList();
                    var countApplied = itemsSelected.Sum(t => t.Quantity);

                    if (countApplied < minApplied)
                    {
                        if (!string.IsNullOrEmpty(error))
                        {
                            error += "\n";
                        }
                        error += string.Format(AppResources.ChooseRequired, minApplied + " " + subMenuModifierGroup.DisplayName + " -");
                    }
                }

                if (string.IsNullOrEmpty(error))
                {
                    ModifierItemView.IsSelected = true;
                    ModifierItemView.Save();
                    await Navigation.PopAsync().ConfigureAwait(false);
                }
                else
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        var notificator = DependencyService.Get <IToastNotificator>();
                        await notificator.Notify(ToastNotificationType.Error, AppResources.Error, error, TimeSpan.FromSeconds(5));
                    });
                }
            };
        }
        public void RenderListView(List <RMenuVM> Menus)
        {
            ListMenuItemViews.Clear();
            foreach (var menuHeader in Menus)
            {
                ObservableCollection <MenuItemViewModel> menuItemViews = new ObservableCollection <MenuItemViewModel>();
                RestaurantMenuListView restaurantMenuListView          = new RestaurantMenuListView();
                foreach (var menuSection in menuHeader.MenuGroups)
                {
                    MenuItemViewModel menuItemView = new MenuItemViewModel();
                    menuItemView.SectionName   = menuSection.Group.DisplayName;
                    menuItemView.SectionDetail = menuSection.Group.DetailedDescription;

                    menuItemViews.Add(menuItemView);
                    foreach (var menuItem in menuSection.MenuItems)
                    {
                        if (!menuItem.MenuItem.ComboOnly)
                        {
                            menuItemView = new MenuItemViewModel();
                            menuItemView.RestaurantMenuItem = new RestaurantMenuItemViewModel()
                            {
                                Id                  = menuItem.MenuItem.ID,
                                MenuId              = menuHeader.Menu.ID,
                                DisplayName         = menuItem.MenuItem.DisplayName,
                                BasePrice           = menuItem.MenuItem.BasePrice,
                                DetailedDescription = menuItem.MenuItem.DetailedDescription,
                                MenuItemVM          = menuItem
                            };
                            menuItemView.PropertyChanged += (sender, e) =>
                            {
                                if (e.PropertyName == nameof(menuItemView.IsSelected))
                                {
                                    CheckCheckout();
                                }
                            };
                            menuItemViews.Add(menuItemView);
                        }
                    }
                }
                bool restaurantMenuListViewItemTapping = false;
                restaurantMenuListView.ListViewMenus.ItemTapped += async(sender, e) =>
                {
                    if (!restaurantMenuListViewItemTapping)
                    {
                        restaurantMenuListViewItemTapping = true;
                        if (e.Item != null)
                        {
                            var menuItemView = e.Item as MenuItemViewModel;
                            restaurantMenuListView.ListViewMenus.SelectedItem = null;
                            if (menuItemView.IsMenuItem)
                            {
                                if (menuItemView.IsEnabled)
                                {
                                    var name = menuItemView.RestaurantMenuItem.DisplayName;
                                    var restaurantMenuItemModifierPage = new RestaurantMenuItemModifierPage(RestaurantVM, menuItemView);
                                    await Utils.PushAsync(Navigation, restaurantMenuItemModifierPage, true);

                                    restaurantMenuItemModifierPage.Saved += (obj) =>
                                    {
                                        //var menuItemViewModels = (sender as ListView).ItemsSource.Cast<MenuItemViewModel>().ToList();
                                        //var index = menuItemViewModels.IndexOf(menuItemView);
                                        //foreach (var menuItemViewModel in menuItemViewModels.Skip(index - 10).Take(10))
                                        //{
                                        //	menuItemViewModel.NeedUpdateSize();
                                        //}
                                    };
                                }
                                else
                                {
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        if (this.Navigation.NavigationStack.LastOrDefault() == this && IsAppearing)
                                        {
                                            DisplayAlert(AppResources.MenuIsClosed, CheckMenuAvailableText, AppResources.OK);
                                        }
                                    });
                                }
                            }
                        }
                        restaurantMenuListViewItemTapping = false;
                    }
                };
                GridMenuItems.Children.Add(restaurantMenuListView);
                restaurantMenuListView.ListViewMenus.ItemsSource = menuItemViews;
                restaurantMenuListView.ListViewMenus.IsVisible   = menuItemViews != null && menuItemViews.Count > 0;
                ListMenuItemViews.Add(menuHeader.Menu.ID, menuItemViews);
            }
        }