Reset selection when leaving menu and a sub menu is still open

This commit is contained in:
Peter Kirmeier 2023-08-16 21:10:41 +02:00
parent 23ac75ea1c
commit 37dda6879f
3 changed files with 20 additions and 3 deletions

View file

@ -5,7 +5,6 @@
namespace SystemTrayMenu.DataClasses
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;

View file

@ -173,6 +173,7 @@
<ListView x:Name="dgv" x:FieldModifier="internal" Margin="6,0" d:ItemsSource="{d:SampleData ItemCount=5}" SelectionMode="Single" HorizontalContentAlignment="Stretch"
Foreground="{x:Static stm:MenuDefines.ColorForeground}" BorderBrush="{x:Null}" Background="{x:Null}"
SelectionChanged="ListView_SelectionChanged" MouseLeave="ListView_MouseLeave"
ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.ScrollChanged="HandleScrollChanged">
<ListView.ItemTemplate>
<DataTemplate>

View file

@ -19,7 +19,6 @@ namespace SystemTrayMenu.UserInterface
using SystemTrayMenu.DllImports;
using SystemTrayMenu.Properties;
using SystemTrayMenu.Utilities;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
/// <summary>
/// Logic of Menu window.
@ -179,7 +178,6 @@ namespace SystemTrayMenu.UserInterface
Command = new ActionCommand((_) => textBoxSearch.SelectAll()),
});
dgv.SelectionChanged += ListView_SelectionChanged;
((INotifyCollectionChanged)dgv.Items).CollectionChanged += (_, _) =>
{
int count = dgv.Items.Count;
@ -1090,6 +1088,25 @@ namespace SystemTrayMenu.UserInterface
}
}
private void ListView_MouseLeave(object sender, MouseEventArgs e)
{
// In case a sub menu is alread open and another item was already selected
// but WaitToLoadMenu hasn't take action yet
// then we want to reset that selection, so the sub menu selection remains active only
if (SubMenu != null)
{
ListView lv = (ListView)sender;
foreach (RowData itemData in lv.Items)
{
if (itemData.SubMenu == SubMenu)
{
lv.SelectedItem = itemData;
break;
}
}
}
}
private void ListViewItem_MouseEnter(object sender, MouseEventArgs e)
{
if (!isShellContextMenuOpen)