Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lost of publishing expanded state from source to target #214

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion samples/TreeDataGridDemo/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@
Source="{Binding DragDrop.Source}"
AutoDragDropRows="True"
RowDragStarted="DragDrop_RowDragStarted"
RowDragOver="DragDrop_RowDragOver"/>
RowDragOver="DragDrop_RowDragOver"
PointerPressed="DragDrop_OnPointerPressed"/>
</DockPanel>
</TabItem>
</TabControl>
Expand Down
12 changes: 12 additions & 0 deletions samples/TreeDataGridDemo/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TreeDataGridRow>();

if (row?.DataContext is DragDropItem item)
item.IsExpanded = !item.IsExpanded;
}
}
}
7 changes: 7 additions & 0 deletions samples/TreeDataGridDemo/Models/DragDropItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DragDropItem : ReactiveObject
private ObservableCollection<DragDropItem>? _children;
private bool _allowDrag = true;
private bool _allowDrop = true;
private bool _isExpanded;

public DragDropItem(string name) => Name = name;
public string Name { get; }
Expand All @@ -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<DragDropItem> Children => _children ??= CreateRandomItems();

public static ObservableCollection<DragDropItem> CreateRandomItems()
Expand Down
4 changes: 3 additions & 1 deletion samples/TreeDataGridDemo/ViewModels/DragDropPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DragDropItem>(
"Allow Drag",
x => x.AllowDrag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading