Disable selection animation for now

This commit is contained in:
TheXamlGuy
2024-06-24 20:07:27 +01:00
parent 590bc61d70
commit 7a56e0dd5e
5 changed files with 71 additions and 44 deletions
+13
View File
@@ -34,6 +34,17 @@ public class ContentTemplate :
} }
} }
async void HandleDataContextChanged(object? sender, EventArgs args)
{
if (control.DataContext is object content)
{
if (content is IActivated activated)
{
await activated.Activated();
}
}
}
async void HandleUnloaded(object? sender, RoutedEventArgs args) async void HandleUnloaded(object? sender, RoutedEventArgs args)
{ {
control.Unloaded -= HandleUnloaded; control.Unloaded -= HandleUnloaded;
@@ -48,6 +59,8 @@ public class ContentTemplate :
control.Loaded += HandleLoaded; control.Loaded += HandleLoaded;
control.Unloaded += HandleUnloaded; control.Unloaded += HandleUnloaded;
control.DataContextChanged += HandleDataContextChanged; ;
return control; return control;
} }
} }
+49 -35
View File
@@ -144,6 +144,18 @@ public partial class ObservableCollection<TItem> :
} }
} }
public virtual Task Activated()
{
IsActivated = true;
while (pendingEvents.Count > 0)
{
object current = pendingEvents.Dequeue();
Handle((dynamic)current);
}
return Task.CompletedTask;
}
public TItem Add<T>(params object?[] parameters) public TItem Add<T>(params object?[] parameters)
where T : where T :
TItem TItem
@@ -240,6 +252,15 @@ public partial class ObservableCollection<TItem> :
void ICollection.CopyTo(Array array, int index) => void ICollection.CopyTo(Array array, int index) =>
collection.CopyTo((TItem[])array, index); collection.CopyTo((TItem[])array, index);
public virtual Task Deactivated()
{
IsActivated = false;
return Task.CompletedTask;
}
public virtual Task Deactivating() =>
Task.CompletedTask;
public virtual void Dispose() public virtual void Dispose()
{ {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@@ -395,6 +416,21 @@ public partial class ObservableCollection<TItem> :
IsCompatibleObject(value) ? IsCompatibleObject(value) ?
IndexOf((TItem)value!) : -1; IndexOf((TItem)value!) : -1;
public virtual Task Initialize()
{
if (IsInitialized)
{
return Task.CompletedTask;
}
IsInitialized = true;
Subscriber.Subscribe(this);
Synchronize();
return Task.CompletedTask;
}
public TItem Insert<T>(int index = 0, public TItem Insert<T>(int index = 0,
params object?[] parameters) params object?[] parameters)
where T : where T :
@@ -479,41 +515,6 @@ public partial class ObservableCollection<TItem> :
return true; return true;
} }
public virtual Task Activated()
{
IsActivated = true;
while (pendingEvents.Count > 0)
{
object current = pendingEvents.Dequeue();
Handle((dynamic)current);
}
return Task.CompletedTask;
}
public virtual Task Deactivated()
{
IsActivated = false;
return Task.CompletedTask;
}
public virtual Task Deactivating() =>
Task.CompletedTask;
public virtual Task Initialize()
{
if (IsInitialized)
{
return Task.CompletedTask;
}
IsInitialized = true;
Subscriber.Subscribe(this);
Synchronize();
return Task.CompletedTask;
}
public bool Remove(TItem item) public bool Remove(TItem item)
{ {
int index = collection.IndexOf(item); int index = collection.IndexOf(item);
@@ -582,6 +583,7 @@ public partial class ObservableCollection<TItem> :
SynchronizeExpression expression = BuildAggregateExpression(); SynchronizeExpression expression = BuildAggregateExpression();
Publisher.PublishUI(expression.Value, expression.Key); Publisher.PublishUI(expression.Value, expression.Key);
} }
public void Track<T>(string propertyName, Func<T> getter, Action<T> setter) public void Track<T>(string propertyName, Func<T> getter, Action<T> setter)
{ {
if (!trackedProperties.ContainsKey(propertyName)) if (!trackedProperties.ContainsKey(propertyName))
@@ -616,6 +618,7 @@ public partial class ObservableCollection<TItem> :
collection.Insert(index > Count ? Count : index, item); collection.Insert(index > Count ? Count : index, item);
} }
protected virtual void RemoveItem(int index) => protected virtual void RemoveItem(int index) =>
collection.RemoveAt(index); collection.RemoveAt(index);
@@ -631,6 +634,17 @@ public partial class ObservableCollection<TItem> :
CollectionChanged?.Invoke(this, args); CollectionChanged?.Invoke(this, args);
} }
partial void OnIsActivatedChanged(bool value)
{
if (value)
{
while (pendingEvents.Count > 0)
{
object current = pendingEvents.Dequeue();
Handle((dynamic)current);
}
}
}
partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue) partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
{ {
if (oldValue is ISelectable oldSelection) if (oldValue is ISelectable oldSelection)
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record SelectionEventArgs<TValue>(TValue? Value); public record SelectionEventArgs<TSender>(TSender? Sender);
@@ -2,7 +2,6 @@
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.Xaml.Interactivity; using Avalonia.Xaml.Interactivity;
using System.Collections; using System.Collections;
using Toolkit.Foundation;
using Toolkit.UI.Controls.Avalonia; using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.UI.Avalonia; namespace Toolkit.UI.Avalonia;
@@ -19,9 +18,9 @@ public class InvokeNavigationViewItemAction :
{ {
if (navigationViewItem.MenuItemsSource is IList collection) if (navigationViewItem.MenuItemsSource is IList collection)
{ {
if (collection is { Count: > 0 } && collection[0] is ISelectable selectable) if (collection is { Count: > 0 })
{ {
selectable.IsSelected = true; navigationViewItem.SetValue(NavigationView.SelectedItemProperty, collection[0]);
} }
} }
}, DispatcherPriority.ContextIdle); }, DispatcherPriority.ContextIdle);
@@ -29,13 +28,13 @@ public class InvokeNavigationViewItemAction :
if (sender is NavigationView navigationView) if (sender is NavigationView navigationView)
{ {
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Invoke(() =>
{ {
if (navigationView.MenuItemsSource is IList collection) if (navigationView.MenuItemsSource is IList collection)
{ {
if (collection is { Count: > 0 } && collection[0] is ISelectable selectable) if (collection is { Count: > 0 })
{ {
selectable.IsSelected = true; navigationView.SetValue(NavigationView.SelectedItemProperty, collection[0]);
} }
} }
}, DispatcherPriority.ContextIdle); }, DispatcherPriority.ContextIdle);
@@ -43,4 +42,5 @@ public class InvokeNavigationViewItemAction :
return true; return true;
} }
} }
@@ -14,6 +14,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0-rc1" /> <PackageReference Include="Avalonia" Version="11.1.0-rc1" />
<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" /> <PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview5" /> <PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview6" />
</ItemGroup> </ItemGroup>
</Project> </Project>