Reselect already selected NavBarListBox item
MODIFY
WalletWasabi.Fluent/Controls/NavBarListBox.cs
WalletWasabi.Fluent/Controls/NavBarListBox.cs
@@ -2,6 +2,8 @@ using Avalonia.Controls;
using Avalonia.Controls.Generators;
using Avalonia.Styling;
using System;
+using Avalonia;
+using Avalonia.Input;
namespace WalletWasabi.Fluent.Controls
{
@@ -9,6 +11,18 @@ namespace WalletWasabi.Fluent.Controls
{
Type IStyleable.StyleKey => typeof(ListBox);
+ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
+ {
+ base.OnAttachedToVisualTree(e);
+
+ this.GetObservable(SelectedItemProperty).Subscribe(OnSelectedItemPropertyChanged);
+ }
+
+ private void OnSelectedItemPropertyChanged(object? obj)
+ {
+ Console.WriteLine($"OnSelectedItemPropertyChanged {obj?.GetType().Name}");
+ }
+
protected override IItemContainerGenerator CreateItemContainerGenerator()
{
return new ItemContainerGenerator<NavBarItem>(
@@ -16,5 +30,24 @@ namespace WalletWasabi.Fluent.Controls
ContentControl.ContentProperty,
ContentControl.ContentTemplateProperty);
}
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ var previousSelectedItem = SelectedItem;
+ // Console.WriteLine($"BEFORE OnPointerPressed {SelectedItem?.GetType().Name}");
+
+ base.OnPointerPressed(e);
+
+ // Console.WriteLine($"AFTER OnPointerPressed {SelectedItem?.GetType().Name}");
+
+ var isSameSelectedItem = previousSelectedItem is not null && previousSelectedItem == SelectedItem;
+ Console.WriteLine($"OnPointerPressed {isSameSelectedItem}");
+ if (isSameSelectedItem)
+ {
+ Console.WriteLine($"RESELECT OnPointerPressed");
+ SelectedItem = null;
+ SelectedItem = previousSelectedItem;
+ }
+ }
}
}

MODIFY
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
WalletWasabi.Fluent/ViewModels/NavBar/NavBarViewModel.cs
@@ -166,6 +166,7 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
private void SetSelectedItem(NavBarItemViewModel? value)
{
+ // Console.WriteLine($"NAVBAR SetSelectedItem {value?.GetType().Name}");
if (value is null || value.SelectionMode == NavBarItemSelectionMode.Selected)
{
Select(value);
@@ -228,6 +229,7 @@ namespace WalletWasabi.Fluent.ViewModels.NavBar
private void NavigateItem(NavBarItemViewModel x)
{
+ // Console.WriteLine($"NAVBAR NavigateItem {x?.GetType().Name}");
if (!_isNavigating)
{
_isNavigating = true;

Reselect already selected NavBarListBox item