增加鼠标悬停切换菜单

This commit is contained in:
liufei
2022-01-22 14:18:16 +08:00
parent 683b4bc870
commit ca3d6b50e3
2 changed files with 40 additions and 14 deletions

View File

@@ -21,8 +21,7 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}" /> <Setter Property="FocusVisualStyle" Value="{x:Null}" />
<EventSetter Event="MouseLeftButtonDown" Handler="MenuClick"/> <EventSetter Event="MouseEnter" Handler="Menu_MouseEnter"/>
<EventSetter Event="MouseRightButtonDown" Handler="MenuClick"/>
<Style.Triggers> <Style.Triggers>
<MultiTrigger> <MultiTrigger>
<MultiTrigger.Conditions> <MultiTrigger.Conditions>
@@ -94,7 +93,7 @@
BorderThickness="0" Foreground="{x:Null}" BorderThickness="0" Foreground="{x:Null}"
SelectedIndex="{Binding AppConfig.SelectedMenuIndex}" SelectedIndex="{Binding AppConfig.SelectedMenuIndex}"
VirtualizingPanel.VirtualizationMode="Recycling" VirtualizingPanel.VirtualizationMode="Recycling"
SelectionChanged="menus_SelectionChanged" SelectionChanged="Menu_SelectionChanged"
> >
<ListBox.Resources> <ListBox.Resources>
<ContextMenu x:Key="MenuDialog" Width="200"> <ContextMenu x:Key="MenuDialog" Width="200">
@@ -122,7 +121,7 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel MouseLeftButtonDown="MenuClick" MouseRightButtonDown="MenuClick" Tag="{Binding}"> <StackPanel Tag="{Binding}">
<TextBox Text="{Binding Path=MenuName, Mode=TwoWay}" <TextBox Text="{Binding Path=MenuName, Mode=TwoWay}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}, ConverterParameter=35}" Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}, ConverterParameter=35}"

View File

@@ -1,16 +1,17 @@
using DraggAnimatedPanelExample; using DraggAnimatedPanelExample;
using GeekDesk.Control.Windows; using GeekDesk.Control.Windows;
using GeekDesk.MyThread;
using GeekDesk.Util; using GeekDesk.Util;
using GeekDesk.ViewModel; using GeekDesk.ViewModel;
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading;
namespace GeekDesk.Control.UserControls.PannelCard namespace GeekDesk.Control.UserControls.PannelCard
{ {
@@ -60,13 +61,13 @@ namespace GeekDesk.Control.UserControls.PannelCard
} }
} }
////菜单点击事件 //////菜单点击事件
private void MenuClick(object sender, MouseButtonEventArgs e) //private void MenuClick(object sender, MouseButtonEventArgs e)
{ //{
//设置对应菜单的图标列表 // //设置对应菜单的图标列表
MenuInfo mi = (MenuInfo)(((StackPanel)sender).Tag); // MenuInfo mi = (MenuInfo)(((StackPanel)sender).Tag);
appData.AppConfig.SelectedMenuIcons = mi.IconList; // appData.AppConfig.SelectedMenuIcons = mi.IconList;
} //}
/// <summary> /// <summary>
/// 当修改菜单元素可见时 设置原菜单为不可见 并且不可选中 /// 当修改菜单元素可见时 设置原菜单为不可见 并且不可选中
@@ -202,7 +203,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
IconfontWindow.Show(SvgToGeometry.GetIconfonts(), menuInfo); IconfontWindow.Show(SvgToGeometry.GetIconfonts(), menuInfo);
} }
private void menus_SelectionChanged(object sender, SelectionChangedEventArgs e) private void Menu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
//设置对应菜单的图标列表 //设置对应菜单的图标列表
if (MenuListBox.SelectedIndex == -1) if (MenuListBox.SelectedIndex == -1)
@@ -214,5 +215,31 @@ namespace GeekDesk.Control.UserControls.PannelCard
appData.AppConfig.SelectedMenuIcons = appData.MenuList[MenuListBox.SelectedIndex].IconList; appData.AppConfig.SelectedMenuIcons = appData.MenuList[MenuListBox.SelectedIndex].IconList;
} }
} }
/// <summary>
/// 鼠标悬停切换菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Menu_MouseEnter(object sender, MouseEventArgs e)
{
if (appData.AppConfig.HoverMenu)
{
new Thread(() =>
{
Thread.Sleep(200);
this.Dispatcher.Invoke(() =>
{
ListBoxItem lbi = sender as ListBoxItem;
if (lbi.IsMouseOver)
{
int index = MenuListBox.ItemContainerGenerator.IndexFromContainer(lbi);
MenuListBox.SelectedIndex = index;
}
});
}).Start();
}
}
} }
} }