fix selection in MenuFlyout
ADD
WalletWasabi.Fluent/Behaviors/MenuFlyoutSelectedItemBehavior.cs
+using System;
+using System.Reactive.Disposables;
+using System.Reactive.Linq;
+using Avalonia;
+using Avalonia.Controls;
+using WalletWasabi.Extensions;
+using WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles;
+
+namespace WalletWasabi.Fluent.Behaviors
+{
+ public class MenuFlyoutSelectedItemBehavior : DisposingBehavior<MenuFlyout>
+ {
+ public static readonly StyledProperty<TimePeriodOption> CurrentTimePeriodOptionProperty =
+ AvaloniaProperty.Register<MenuFlyoutSelectedItemBehavior, TimePeriodOption>(nameof(CurrentTimePeriodOption));
+
+ public TimePeriodOption CurrentTimePeriodOption
+ {
+ get => GetValue(CurrentTimePeriodOptionProperty);
+ set => SetValue(CurrentTimePeriodOptionProperty, value);
+ }
+
+ protected override void OnAttached(CompositeDisposable disposables)
+ {
+ if (AssociatedObject is null)
+ {
+ return;
+ }
+
+ Observable
+ .FromEventPattern(AssociatedObject, nameof(AssociatedObject.Opened))
+ .Subscribe(_ =>
+ {
+ foreach (var item in AssociatedObject.Items)
+ {
+ if (item is MenuItem mi && (string) mi.Header == CurrentTimePeriodOption.FriendlyName())
+ {
+ mi.IsSelected = true;
+ }
+ }
+ })
+ .DisposeWith(disposables);
+ }
+ }
+}

MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
@@ -9,9 +9,33 @@ using NBitcoin;
using ReactiveUI;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Wallets.Home.History;
+using WalletWasabi.Models;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
+ public enum TimePeriodOption
+ {
+ All,
+
+ [FriendlyName("1D")]
+ Day,
+
+ [FriendlyName("1W")]
+ Week,
+
+ [FriendlyName("1M")]
+ Month,
+
+ [FriendlyName("3M")]
+ ThreeMonths,
+
+ [FriendlyName("6M")]
+ SixMonths,
+
+ [FriendlyName("1Y")]
+ Year
+ }
+
public partial class WalletBalanceChartTileViewModel : TileViewModel
{
private readonly ObservableCollection<HistoryItemViewModel> _history;
@@ -20,7 +44,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
[AutoNotify] private double? _xMinimum;
[AutoNotify] private List<string>? _yLabels;
[AutoNotify] private List<string>? _xLabels;
- private TimePeriodOption _currentTimePeriod = TimePeriodOption.ThreeMonths;
+ [AutoNotify] private TimePeriodOption _currentTimePeriod = TimePeriodOption.ThreeMonths;
public WalletBalanceChartTileViewModel(ObservableCollection<HistoryItemViewModel> history)
{
@@ -37,17 +61,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
AllCommand = ReactiveCommand.Create(() => { UpdateSample(TimePeriodOption.All); });
}
- private enum TimePeriodOption
- {
- All,
- Day,
- Week,
- Month,
- ThreeMonths,
- SixMonths,
- Year
- }
-
public ICommand DayCommand { get; }
public ICommand WeekCommand { get; }
@@ -115,7 +128,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
break;
}
- _currentTimePeriod = timePeriod;
+ CurrentTimePeriod = timePeriod;
}
private void UpdateSample(TimeSpan sampleTime, TimeSpan sampleBackFor)

MODIFY
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartSmallTileView.axaml
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartSmallTileView.axaml
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:c="using:WalletWasabi.Fluent.Controls"
xmlns:vm="using:WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles"
+ xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
+ xmlns:behaviors="using:WalletWasabi.Fluent.Behaviors"
mc:Ignorable="d" d:DesignWidth="330" d:DesignHeight="150"
x:CompileBindings="True" x:DataType="vm:WalletBalanceChartTileViewModel"
x:Class="WalletWasabi.Fluent.Views.Wallets.Home.Tiles.WalletBalanceChart.WalletBalanceChartSmallTileView">
<Button Classes="plain" DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="0 0 0 -3">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
+ <i:Interaction.Behaviors>
+ <behaviors:MenuFlyoutSelectedItemBehavior CurrentTimePeriodOption="{Binding CurrentTimePeriod}" />
+ </i:Interaction.Behaviors>
<MenuItem Header="All" Command="{Binding AllCommand}" />
<MenuItem Header="1D" Command="{Binding DayCommand}" />
<MenuItem Header="1W" Command="{Binding WeekCommand}" />

fix selection in MenuFlyout