Example #1
0
        protected TabControl()
        {
            Dropdown = CreateDropdown();
            if (Dropdown != null)
            {
                Dropdown.RelativeSizeAxes = Axes.X;
                Dropdown.Anchor           = Anchor.TopRight;
                Dropdown.Origin           = Anchor.TopRight;
                Dropdown.Current.BindTo(Current);

                Add(Dropdown);

                Trace.Assert((Dropdown.Header.Anchor & Anchor.x2) > 0, $@"The {nameof(Dropdown)} implementation should use a right-based anchor inside a TabControl.");
                Trace.Assert((Dropdown.Header.RelativeSizeAxes & Axes.X) == 0, $@"The {nameof(Dropdown)} implementation's header should have a specific size.");

                // create tab items for already existing items in dropdown (if any).
                tabMap = Dropdown.Items.ToDictionary(item => item.Value, item => addTab(item.Value, false));
            }
            else
            {
                tabMap = new Dictionary <T, TabItem <T> >();
            }

            Add(TabContainer = new TabFillFlowContainer <TabItem <T> >
            {
                Direction            = FillDirection.Full,
                RelativeSizeAxes     = Axes.Both,
                Depth                = -1,
                Masking              = true,
                TabVisibilityChanged = updateDropdown,
                ChildrenEnumerable   = tabMap.Values
            });

            Current.ValueChanged += newSelection =>
            {
                if (IsLoaded)
                {
                    SelectTab(tabMap[Current]);
                }
                else
                {
                    //will be handled in LoadComplete
                    SelectedTab = tabMap[Current];
                }
            };
        }
Example #2
0
        protected TabControl()
        {
            Dropdown = CreateDropdown();
            if (Dropdown != null)
            {
                Dropdown.RelativeSizeAxes = Axes.X;
                Dropdown.Anchor           = Anchor.TopRight;
                Dropdown.Origin           = Anchor.TopRight;
                Dropdown.Current.BindTo(Current);

                AddInternal(Dropdown);

                Trace.Assert(Dropdown.Header.Anchor.HasFlag(Anchor.x2), $@"The {nameof(Dropdown)} implementation should use a right-based anchor inside a TabControl.");
                Trace.Assert(!Dropdown.Header.RelativeSizeAxes.HasFlag(Axes.X), $@"The {nameof(Dropdown)} implementation's header should have a specific size.");

                // create tab items for already existing items in dropdown (if any).
                tabMap = Dropdown.Items.ToDictionary(item => item, item => addTab(item, false));
            }
            else
            {
                tabMap = new Dictionary <T, TabItem <T> >();
            }

            AddInternal(TabContainer          = CreateTabFlow());
            TabContainer.TabVisibilityChanged = updateDropdown;
            TabContainer.ChildrenEnumerable   = tabMap.Values;

            Current.ValueChanged += newSelection =>
            {
                if (IsLoaded)
                {
                    SelectTab(tabMap[Current]);
                }
                else
                {
                    //will be handled in LoadComplete
                    SelectedTab = tabMap[Current];
                }
            };
        }