chr
2024-08-07 22beee93f14d042aa184148c53efb79e23416526
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
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
 
namespace PdmSwPlugin.Common.Control.TreeGrid
{
    public class TreeDataGrid : DataGrid
    {
        public event EventHandler<bool> ExpandedChange;
 
        public virtual void OnExpandedChange(bool expand) { 
            ExpandedChange?.Invoke(this, expand);
        }
 
        static TreeDataGrid() {
            //ScrollViewer.HorizontalScrollBarVisibilityProperty
            //    .OverrideMetadata(typeof(TreeDataGrid), new FrameworkPropertyMetadata(ScrollBarVisibility.Disabled));
            //ScrollViewer.VerticalScrollBarVisibilityProperty
            //    .OverrideMetadata(typeof(TreeDataGrid), new FrameworkPropertyMetadata(ScrollBarVisibility.Disabled));
        }
 
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new TreeDataGridRow();
        }
 
    }
 
    public class TreeDataGridRow : DataGridRow
    {
 
        public TreeDataGridRow()
        {
            this.DataContextChanged += TreeGridItem_DataContextChanged;
        }
 
        private void TreeGridItem_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue != null && e.OldValue is TreeItemData oldTreeData)
            {
                oldTreeData.VisibleChange -= DataVisiableChange;
            }
            if (DataContext != null && DataContext is TreeItemData treeData)
            {
                treeData.VisibleChange += DataVisiableChange;
            }
        }
 
        private void DataVisiableChange(object sender, bool visiable)
        {
            object parent = ItemsControl.ItemsControlFromItemContainer(this);
            if (parent != null && parent is TreeDataGrid treeDataGrid) {
                treeDataGrid.OnExpandedChange(visiable);
            }
        }
    }
}