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);
|
}
|
}
|
}
|
}
|