add listener for context menu

This commit is contained in:
KP9lK 2024-12-11 03:16:14 +03:00
parent 3456af5101
commit 3993a744b2
2 changed files with 20 additions and 3 deletions

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Avalonia.Controls.Selection;
using Tmds.DBus.Protocol;
namespace Presence.Desktop.ViewModels
@ -34,9 +35,10 @@ namespace Presence.Desktop.ViewModels
get => _selectedGroupItem;
set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); }
private bool _MultipleSelected = false;
public bool MultipleSelected { get => _MultipleSelected; set => this.RaiseAndSetIfChanged(ref _MultipleSelected, value); }
public SelectionModel<UserPresenter> Selection { get; }
private GroupPresenter? _selectedGroupItem;
private IGroupUseCase _groupUseCase;
public ObservableCollection<UserPresenter> Users { get => _users;}
public ObservableCollection<UserPresenter> _users;
@ -52,6 +54,9 @@ namespace Presence.Desktop.ViewModels
{ RefreshGroups();
SetUsers();
});
Selection = new SelectionModel<UserPresenter>();
Selection.SingleSelect = false;
Selection.SelectionChanged += SelectionChanged;
}
private void SetUsers()
@ -93,6 +98,11 @@ namespace Presence.Desktop.ViewModels
Console.WriteLine("clock");
SelectedFile = await _SelectFileInteraction.Handle("Chose csv file");
}
void SelectionChanged(object sender, SelectionModelSelectionChangedEventArgs e)
{
MultipleSelected = Selection.SelectedItems.Count > 1;
}
public string? UrlPathSegment { get; }
public IScreen HostScreen { get; }
}

View File

@ -31,7 +31,14 @@
<ComboBox/>
</StackPanel>
<Border>
<ListBox Background="Bisque" ItemsSource="{Binding Users}">
<ListBox SelectionMode="Multiple" Selection="{Binding Selection}" Background="Bisque" ItemsSource="{Binding Users}">
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem IsVisible="{Binding !MultipleSelected}" Header="Remove"/>
<MenuItem IsVisible="{Binding !MultipleSelected}" Header="Edit"/>
<MenuItem IsVisible="{Binding MultipleSelected}" Header="RemoveAll"></MenuItem>
</ContextMenu>
</ListBox.ContextMenu>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">