コード例 #1
0
        internal static Size GetDesiredSizeWithoutMargin(UIElement element)
        {
            // We have a hard coded margin value on each side for the
            // selected item. To account for this additional size,
            // we add this size to the calculations taking place.
            double  selectedMarginSize = 0;
            TabItem tabItem            = element as TabItem;

            if (tabItem != null && tabItem.IsSelected)
            {
                Panel            panel = tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement) as Panel;
                FrameworkElement fe    = (panel != null && panel.Children.Count > 0) ? panel.Children[0] as FrameworkElement : null;
                if (fe != null)
                {
                    selectedMarginSize += (Math.Abs(fe.Margin.Left + fe.Margin.Right));
                }
            }

            Thickness margin = (Thickness)element.GetValue(MarginProperty);
            Size      desiredSizeWithoutMargin = new Size();

            desiredSizeWithoutMargin.Height = Math.Max(0d, element.DesiredSize.Height - margin.Top - margin.Bottom);
            desiredSizeWithoutMargin.Width  = Math.Max(0d, element.DesiredSize.Width - margin.Left - margin.Right + selectedMarginSize);
            return(desiredSizeWithoutMargin);
        }
コード例 #2
0
        public void UpdateVisualStateTest()
        {
            TabControl tabControl = new TabControl();
            TabItem    tabItem    = new TabItem();

            tabControl.Items.Add(tabItem);
            tabItem.IsSelected = true;

            tabControl.TabStripPlacement = Dock.Top;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateTopSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));

            tabControl.TabStripPlacement = Dock.Bottom;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateBottomSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));

            tabControl.TabStripPlacement = Dock.Left;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateLeftSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));

            tabControl.TabStripPlacement = Dock.Right;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateRightSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));
        }
コード例 #3
0
ファイル: TabPanelTest.cs プロジェクト: ynkbt/moon
        public void GetHeadersSizeTest()
        {
            TabControl tabControl = new TabControl();

            tabControl.Height = 100;
            tabControl.Width  = 200;

            double[] sizes = new double[3];

            TabItem tabItem1 = new TabItem();

            tabItem1.Height = 10;
            tabItem1.Width  = 10;
            TabItem tabItem2 = new TabItem();

            tabItem2.Height = 10;
            tabItem2.Width  = 20;
            TabItem tabItem3 = new TabItem();

            tabItem3.Height = 10;
            tabItem3.Width  = 30;

            tabControl.Items.Add(tabItem1);
            tabControl.Items.Add(tabItem2);
            tabControl.Items.Add(tabItem3);

            FrameworkElement fe = null;
            double           selectedMarginSize = 0;

            CreateAsyncTask(tabControl,
                            () => sizes = tabControl.ElementTabPanelTop.GetHeadersSize(),
                            // First Item Is Selected
                            () => fe = (tabItem1.GetTemplate(tabItem1.IsSelected, tabItem1.TabStripPlacement) as Panel).Children[0] as FrameworkElement,
                            () => selectedMarginSize += (Math.Abs(fe.Margin.Left + fe.Margin.Right)),
                            () => Assert.AreEqual(sizes[0], 10.0 + selectedMarginSize),
                            () => Assert.AreEqual(sizes[1], 20.0),
                            () => Assert.AreEqual(sizes[2], 30.0)
                            );

            EnqueueTestComplete();
        }
コード例 #4
0
ファイル: TabPanelTest.cs プロジェクト: dfr0/moon
        public void GetHeadersSizeTest()
        {
            TabControl tabControl = new TabControl();
            
            tabControl.Height = 100;
            tabControl.Width = 200;

            double[] sizes = new double[3];
            
            TabItem tabItem1 = new TabItem();
            tabItem1.Height = 10;
            tabItem1.Width = 10;
            TabItem tabItem2 = new TabItem();
            tabItem2.Height = 10;
            tabItem2.Width = 20;
            TabItem tabItem3 = new TabItem();
            tabItem3.Height = 10;
            tabItem3.Width = 30;

            tabControl.Items.Add(tabItem1);
            tabControl.Items.Add(tabItem2);
            tabControl.Items.Add(tabItem3);

            FrameworkElement fe = null;
            double selectedMarginSize = 0;
            CreateAsyncTask(tabControl,
                () => sizes = tabControl.ElementTabPanelTop.GetHeadersSize(),
                // First Item Is Selected
                () => fe = (tabItem1.GetTemplate(tabItem1.IsSelected, tabItem1.TabStripPlacement) as Panel).Children[0] as FrameworkElement,
                () => selectedMarginSize += (Math.Abs(fe.Margin.Left + fe.Margin.Right)),
                () => Assert.AreEqual(sizes[0], 10.0 + selectedMarginSize),
                () => Assert.AreEqual(sizes[1], 20.0),
                () => Assert.AreEqual(sizes[2], 30.0)
            );

            EnqueueTestComplete();
        }
コード例 #5
0
ファイル: TabItemTest.cs プロジェクト: dfr0/moon
        public void UpdateVisualStateTest()
        {
            TabControl tabControl = new TabControl();
            TabItem tabItem = new TabItem();
            tabControl.Items.Add(tabItem);
            tabItem.IsSelected = true;

            tabControl.TabStripPlacement = Dock.Top;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateTopSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));

            tabControl.TabStripPlacement = Dock.Bottom;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateBottomSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));
            
            tabControl.TabStripPlacement = Dock.Left;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateLeftSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));

            tabControl.TabStripPlacement = Dock.Right;
            tabItem.UpdateVisualState();
            Assert.AreEqual(tabItem.ElementTemplateRightSelected, tabItem.GetTemplate(tabItem.IsSelected, tabItem.TabStripPlacement));
        }