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)
{
control.Unloaded -= HandleUnloaded;
@@ -48,6 +59,8 @@ public class ContentTemplate :
control.Loaded += HandleLoaded;
control.Unloaded += HandleUnloaded;
control.DataContextChanged += HandleDataContextChanged; ;
return control;
}
}
+50 -36
View File
@@ -144,8 +144,20 @@ 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)
where T :
where T :
TItem
{
T? item = Factory.Create<T>(args =>
@@ -240,6 +252,15 @@ public partial class ObservableCollection<TItem> :
void ICollection.CopyTo(Array array, int 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()
{
GC.SuppressFinalize(this);
@@ -395,6 +416,21 @@ public partial class ObservableCollection<TItem> :
IsCompatibleObject(value) ?
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,
params object?[] parameters)
where T :
@@ -479,41 +515,6 @@ public partial class ObservableCollection<TItem> :
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)
{
int index = collection.IndexOf(item);
@@ -582,6 +583,7 @@ public partial class ObservableCollection<TItem> :
SynchronizeExpression expression = BuildAggregateExpression();
Publisher.PublishUI(expression.Value, expression.Key);
}
public void Track<T>(string propertyName, Func<T> getter, Action<T> setter)
{
if (!trackedProperties.ContainsKey(propertyName))
@@ -616,6 +618,7 @@ public partial class ObservableCollection<TItem> :
collection.Insert(index > Count ? Count : index, item);
}
protected virtual void RemoveItem(int index) =>
collection.RemoveAt(index);
@@ -631,6 +634,17 @@ public partial class ObservableCollection<TItem> :
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)
{
if (oldValue is ISelectable oldSelection)
+1 -1
View File
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation;
public record SelectionEventArgs<TValue>(TValue? Value);
public record SelectionEventArgs<TSender>(TSender? Sender);
@@ -2,7 +2,6 @@
using Avalonia.Threading;
using Avalonia.Xaml.Interactivity;
using System.Collections;
using Toolkit.Foundation;
using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.UI.Avalonia;
@@ -19,9 +18,9 @@ public class InvokeNavigationViewItemAction :
{
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);
@@ -29,13 +28,13 @@ public class InvokeNavigationViewItemAction :
if (sender is NavigationView navigationView)
{
Dispatcher.UIThread.Post(() =>
Dispatcher.UIThread.Invoke(() =>
{
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);
@@ -43,4 +42,5 @@ public class InvokeNavigationViewItemAction :
return true;
}
}
@@ -14,6 +14,6 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0-rc1" />
<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>
</Project>