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 Columns { get { return (ObservableCollection)GetValue(ColumnsProperty); } set { SetValue(ColumnsProperty, value); } } public static readonly DependencyProperty ColumnsProperty = DependencyProperty.Register("Columns", typeof(ObservableCollection), typeof(DiagnosticsGrid), new PropertyMetadata(null, (d, e) => (d as DiagnosticsGrid).LoadDefinitions())); public ObservableCollection Rows { get { return (ObservableCollection)GetValue(RowsProperty); } set { SetValue(RowsProperty, value); } } public static readonly DependencyProperty RowsProperty = DependencyProperty.Register("Rows", typeof(ObservableCollection), 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(); } } }