Beispiel #1
0
            public MenuItemCreator(ViewGroup root, NavigationManager.MainMenuSelections mainMenuSelection, MainScreenView mainScreenView)
            {
                _mainScreenView    = mainScreenView;
                _mainMenuSelection = mainMenuSelection;
                _mainScreenView.ViewModel.PropertyChanged += new WeakEventHandler <PropertyChangedEventArgs>(ViewModel_PropertyChanged1).Handler;

                TextView textView = new TextView(root.Context)
                {
                    Text             = PowerPlannerResources.GetStringMenuItem(mainMenuSelection),
                    TextSize         = 20,
                    Clickable        = true,
                    LayoutParameters = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MatchParent,
                        LinearLayout.LayoutParams.WrapContent)
                };

                textView.SetTextColor(new Color(255, 255, 255));

                int paddingTopBottom = ThemeHelper.AsPx(root.Context, 11);
                int paddingLeft      = ThemeHelper.AsPx(root.Context, MENU_ITEM_PADDING_LEFT_PX);

                textView.SetPaddingRelative(paddingLeft, paddingTopBottom, 0, paddingTopBottom);

                textView.Click += delegate
                {
                    _mainScreenView.ViewModel.SelectedItem = mainMenuSelection;

                    if (mainMenuSelection != NavigationManager.MainMenuSelections.Classes)
                    {
                        _mainScreenView._drawerLayout.CloseDrawers();
                    }
                };

                if (mainMenuSelection == NavigationManager.MainMenuSelections.Classes)
                {
                    LinearLayout linearLayout = new LinearLayout(root.Context)
                    {
                        Orientation      = Orientation.Vertical,
                        LayoutParameters = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MatchParent,
                            LinearLayout.LayoutParams.WrapContent)
                    };

                    LinearLayout layoutClassesHeaderAndAddButton = new LinearLayout(root.Context)
                    {
                        Orientation      = Orientation.Horizontal,
                        LayoutParameters = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MatchParent,
                            LinearLayout.LayoutParams.WrapContent)
                    };

                    // This width will stretch
                    textView.LayoutParameters.Width = 0;
                    (textView.LayoutParameters as LinearLayout.LayoutParams).Weight = 1;

                    layoutClassesHeaderAndAddButton.AddView(textView);

                    // And then the add class button
                    ImageButton addClassButton = new ImageButton(root.Context)
                    {
                        LayoutParameters = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WrapContent,
                            LinearLayout.LayoutParams.MatchParent),
                        Visibility = ViewStates.Invisible
                    };
                    addClassButton.Background = ThemeHelper.GetAttributeDrawable(root.Context, Resource.Attribute.selectableItemBackground);
                    addClassButton.SetImageDrawable(ContextCompat.GetDrawable(root.Context, Android.Resource.Drawable.IcInputAdd));
                    if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
                    {
                        addClassButton.ImageTintList = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { new Color(255, 255, 255) });
                    }
                    addClassButton.Click += AddClassButton_Click;

                    _mainScreenView._classAddButtonReference = new WeakReference <View>(addClassButton);
                    layoutClassesHeaderAndAddButton.AddView(addClassButton);



                    linearLayout.AddView(layoutClassesHeaderAndAddButton);


                    LinearLayout classesViewGroup = new LinearLayout(root.Context)
                    {
                        Orientation      = Orientation.Vertical,
                        LayoutParameters = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.MatchParent,
                            LinearLayout.LayoutParams.WrapContent),
                        Visibility = ViewStates.Gone
                    };

                    _itemsWrapperClasses = new ItemsControlWrapper(classesViewGroup)
                    {
                        ItemsSource  = _mainScreenView.ViewModel.Classes,
                        ItemTemplate = new CustomDataTemplate <ViewItemClass>(_mainScreenView.CreateClassMenuItem)
                    };

                    _mainScreenView._classesViewGroupReference = new WeakReference <View>(classesViewGroup);

                    linearLayout.AddView(classesViewGroup);

                    View = linearLayout;
                }

                else
                {
                    View = textView;
                }

                UpdateIsSelected();
            }