diff --git a/samples/TreeDataGridDemo/MainWindow.axaml b/samples/TreeDataGridDemo/MainWindow.axaml index 2a1ba4c5..31c178f0 100644 --- a/samples/TreeDataGridDemo/MainWindow.axaml +++ b/samples/TreeDataGridDemo/MainWindow.axaml @@ -134,7 +134,8 @@ Source="{Binding DragDrop.Source}" AutoDragDropRows="True" RowDragStarted="DragDrop_RowDragStarted" - RowDragOver="DragDrop_RowDragOver"/> + RowDragOver="DragDrop_RowDragOver" + PointerPressed="DragDrop_OnPointerPressed"/> diff --git a/samples/TreeDataGridDemo/MainWindow.axaml.cs b/samples/TreeDataGridDemo/MainWindow.axaml.cs index 883cac22..70645d43 100644 --- a/samples/TreeDataGridDemo/MainWindow.axaml.cs +++ b/samples/TreeDataGridDemo/MainWindow.axaml.cs @@ -2,6 +2,7 @@ using System.Linq; using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.LogicalTree; @@ -128,5 +129,16 @@ private void UpdateRealizedCount() var unrealizedRowCount = rows.GetVisualChildren().Count() - realizedRowCount; textBlock.Text = $"{realizedRowCount} rows realized ({unrealizedRowCount} unrealized)"; } + + private void DragDrop_OnPointerPressed(object? sender, PointerPressedEventArgs e) + { + if (e.ClickCount != 2) + return; + + var row = (e.Source as Control)?.FindAncestorOfType(); + + if (row?.DataContext is DragDropItem item) + item.IsExpanded = !item.IsExpanded; + } } } diff --git a/samples/TreeDataGridDemo/Models/DragDropItem.cs b/samples/TreeDataGridDemo/Models/DragDropItem.cs index 73f51de3..ca9b82a7 100644 --- a/samples/TreeDataGridDemo/Models/DragDropItem.cs +++ b/samples/TreeDataGridDemo/Models/DragDropItem.cs @@ -11,6 +11,7 @@ public class DragDropItem : ReactiveObject private ObservableCollection? _children; private bool _allowDrag = true; private bool _allowDrop = true; + private bool _isExpanded; public DragDropItem(string name) => Name = name; public string Name { get; } @@ -27,6 +28,12 @@ public bool AllowDrop set => this.RaiseAndSetIfChanged(ref _allowDrop, value); } + public bool IsExpanded + { + get => _isExpanded; + set => this.RaiseAndSetIfChanged(ref _isExpanded, value); + } + public ObservableCollection Children => _children ??= CreateRandomItems(); public static ObservableCollection CreateRandomItems() diff --git a/samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs b/samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs index e75eb1c4..2590a1a8 100644 --- a/samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs +++ b/samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs @@ -22,7 +22,9 @@ public DragDropPageViewModel() "Name", x => x.Name, GridLength.Star), - x => x.Children), + x => x.Children, + x => x.Children.Count > 0, + x => x.IsExpanded), new CheckBoxColumn( "Allow Drag", x => x.AllowDrag, diff --git a/src/Avalonia.Controls.TreeDataGrid/Experimental/Data/Core/TypedBindingExpression`2.cs b/src/Avalonia.Controls.TreeDataGrid/Experimental/Data/Core/TypedBindingExpression`2.cs index b19341af..d80e99eb 100644 --- a/src/Avalonia.Controls.TreeDataGrid/Experimental/Data/Core/TypedBindingExpression`2.cs +++ b/src/Avalonia.Controls.TreeDataGrid/Experimental/Data/Core/TypedBindingExpression`2.cs @@ -310,15 +310,7 @@ private void ChainPropertyChanged(object? sender) { if (sender is null) return; - - var index = ChainIndexOf(sender); - - if (index != -1) - { - StopListeningToChain(index); - ListenToChain(index); - } - + PublishValue(); }