aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Controls/DiagnosticsGrid.cs
blob: bb647c6f67b66e514de8317ed1238157fdcf2297 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Tango.FSE.Diagnostics.Project;

namespace Tango.FSE.Diagnostics.Controls
{
    public class DiagnosticsGrid : Grid
    {
        public ObservableCollection<DiagnosticsProjectTabColumnDefinition> Columns
        {
            get { return (ObservableCollection<DiagnosticsProjectTabColumnDefinition>)GetValue(ColumnsProperty); }
            set { SetValue(ColumnsProperty, value); }
        }
        public static readonly DependencyProperty ColumnsProperty =
            DependencyProperty.Register("Columns", typeof(ObservableCollection<DiagnosticsProjectTabColumnDefinition>), typeof(DiagnosticsGrid), new PropertyMetadata(null, (d, e) => (d as DiagnosticsGrid).LoadDefinitions()));

        public ObservableCollection<DiagnosticsProjectTabRowDefinition> Rows
        {
            get { return (ObservableCollection<DiagnosticsProjectTabRowDefinition>)GetValue(RowsProperty); }
            set { SetValue(RowsProperty, value); }
        }
        public static readonly DependencyProperty RowsProperty =
            DependencyProperty.Register("Rows", typeof(ObservableCollection<DiagnosticsProjectTabRowDefinition>), typeof(DiagnosticsGrid), new PropertyMetadata(null, (d, e) => (d as DiagnosticsGrid).LoadDefinitions()));

        protected virtual void LoadDefinitions()
        {
            if (Rows != null && Columns != null)
            {
                ColumnDefinitions.Clear();
                RowDefinitions.Clear();

                foreach (var column in Columns)
                {
                    var columnDefinition = new ColumnDefinition() { Width = column.Width };
                    columnDefinition.Bind(ColumnDefinition.WidthProperty, column, nameof(DiagnosticsProjectTabColumnDefinition.Width), System.Windows.Data.BindingMode.TwoWay);
                    ColumnDefinitions.Add(columnDefinition);
                }

                foreach (var row in Rows)
                {
                    var rowDefinition = new RowDefinition() { Height = row.Height };
                    rowDefinition.Bind(RowDefinition.HeightProperty, row, nameof(DiagnosticsProjectTabRowDefinition.Height), System.Windows.Data.BindingMode.TwoWay);
                    RowDefinitions.Add(rowDefinition);
                }

                Columns.CollectionChanged -= Columns_CollectionChanged;
                Rows.CollectionChanged -= Rows_CollectionChanged;
                Columns.CollectionChanged += Columns_CollectionChanged;
                Rows.CollectionChanged += Rows_CollectionChanged;
            }
        }

        private void Rows_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            LoadDefinitions();
        }

        private void Columns_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            LoadDefinitions();
        }
    }
}