More selection edge cases fixed
This commit is contained in:
@@ -29,7 +29,8 @@ public partial class ObservableCollection<TItem> :
|
||||
INotificationHandler<InsertEventArgs<TItem>>,
|
||||
INotificationHandler<MoveEventArgs<TItem>>,
|
||||
INotificationHandler<MoveToEventArgs<TItem>>,
|
||||
INotificationHandler<ReplaceEventArgs<TItem>>
|
||||
INotificationHandler<ReplaceEventArgs<TItem>>,
|
||||
INotificationHandler<SelectionEventArgs<TItem>>
|
||||
where TItem :
|
||||
IDisposable
|
||||
{
|
||||
@@ -43,6 +44,9 @@ public partial class ObservableCollection<TItem> :
|
||||
[ObservableProperty]
|
||||
private int selectedIndex = 0;
|
||||
|
||||
[ObservableProperty]
|
||||
private TItem? selectedItem;
|
||||
|
||||
public ObservableCollection(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
@@ -279,6 +283,15 @@ public partial class ObservableCollection<TItem> :
|
||||
if (args.Value is TItem item)
|
||||
{
|
||||
Insert(args.Index, item);
|
||||
|
||||
if (item is ISelectable selectable)
|
||||
{
|
||||
if (selectable.Selected)
|
||||
{
|
||||
SelectedItem = item;
|
||||
SelectedIndex = this.IndexOf(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -487,6 +500,11 @@ public partial class ObservableCollection<TItem> :
|
||||
added.Selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(SelectionEventArgs<TItem> args)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ObservableCollection<TValue, TViewModel>(IServiceProvider provider,
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Selected
|
||||
{
|
||||
public static SelectedEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
|
||||
public static SelectedEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record SelectedEventArgs<TValue>(TValue? Value);
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Selection
|
||||
{
|
||||
public static SelectionEventArgs<TValue> As<TValue>(TValue value) =>
|
||||
new(value);
|
||||
|
||||
public static SelectionEventArgs<TValue> As<TValue>() where TValue : new() =>
|
||||
new(new TValue());
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record SelectionEventArgs<TValue>(TValue? Value);
|
||||
Reference in New Issue
Block a user