aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Controls/LogTabsGrid.cs
blob: 6641b299e6e0f90c7b31635d5510a1da2e76da49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace Tango.FSE.LogViewer.UI.Controls
{
    public class LogTabsGrid : Grid
    {
        public int Columns
        {
            get { return (int)GetValue(ColumnsProperty); }
            set { SetValue(ColumnsProperty, value); }
        }
        public static readonly DependencyProperty ColumnsProperty =
            DependencyProperty.Register("Columns", typeof(int), typeof(LogTabsGrid), new PropertyMetadata(0, (d, e) => (d as LogTabsGrid).OnColumnsChanged()));

        private void OnColumnsChanged()
        {
            ColumnDefinitions.Clear();

            for (int i = 0; i < Columns; i++)
            {
                ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
            }
        }

        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            base.OnVisualChildrenChanged(visualAdded, visualRemoved);

            for (int i = 0; i < Children.Count; i++)
            {
                var element = Children[i] as FrameworkElement;

                if (element != null)
                {
                    Grid.SetColumn(Children[i] as FrameworkElement, i);
                }
            }
        }
    }
}