优化修改菜单图标时的样式及逻辑
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
</Setter>
|
</Setter>
|
||||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||||
<EventSetter Event="MouseEnter" Handler="Menu_MouseEnter"/>
|
<EventSetter Event="MouseEnter" Handler="Menu_MouseEnter"/>
|
||||||
|
<EventSetter Event="Unselected" Handler="ListBoxItem_Unselected"/>
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<MultiTrigger>
|
<MultiTrigger>
|
||||||
<MultiTrigger.Conditions>
|
<MultiTrigger.Conditions>
|
||||||
@@ -42,24 +43,34 @@
|
|||||||
</Storyboard>
|
</Storyboard>
|
||||||
</BeginStoryboard>
|
</BeginStoryboard>
|
||||||
</MultiTrigger.ExitActions>
|
</MultiTrigger.ExitActions>
|
||||||
|
<MultiTrigger.Setters>
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
|
</MultiTrigger.Setters>
|
||||||
</MultiTrigger>
|
</MultiTrigger>
|
||||||
|
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
|
||||||
<Setter Property="Background" Value="#FFECECEC"/>
|
|
||||||
|
<!--<Trigger Property="IsSelected" Value="False">
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
<Trigger Property="IsSelected" Value="True">
|
<Trigger Property="IsSelected" Value="True">
|
||||||
<Setter Property="Background" Value="#FFECECEC"/>
|
<Setter Property="Background" Value="#ECECEC"/>
|
||||||
<Setter Property="Foreground" Value="Black"/>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
|
|
||||||
<MultiDataTrigger>
|
<Trigger Property="IsMouseOver" Value="False">
|
||||||
<MultiDataTrigger.Conditions>
|
|
||||||
<Condition Binding="{Binding IsEdit}" Value="True"/>
|
|
||||||
</MultiDataTrigger.Conditions>
|
|
||||||
<MultiDataTrigger.Setters>
|
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
</MultiDataTrigger.Setters>
|
<Setter Property="Foreground" Value="Black"/>
|
||||||
</MultiDataTrigger>
|
</Trigger>-->
|
||||||
|
|
||||||
|
<!--<MultiTrigger>
|
||||||
|
<MultiTrigger.Conditions>
|
||||||
|
<Condition Property=""></Condition>
|
||||||
|
</MultiTrigger.Conditions>
|
||||||
|
</MultiTrigger>-->
|
||||||
|
|
||||||
|
|
||||||
</Style.Triggers>
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
@@ -136,7 +147,9 @@
|
|||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
IsVisibleChanged="MenuEditWhenVisibilityChanged"
|
IsVisibleChanged="MenuEditWhenVisibilityChanged"
|
||||||
Visibility="{Binding MenuEdit}"/>
|
Visibility="{Binding MenuEdit}"/>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal"
|
||||||
|
IsVisibleChanged="MenuWhenVisibilityChanged"
|
||||||
|
Visibility="{Binding NotMenuEdit}">
|
||||||
<Button Background="Transparent"
|
<Button Background="Transparent"
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
hc:IconElement.Geometry="{Binding MenuGeometry}"
|
hc:IconElement.Geometry="{Binding MenuGeometry}"
|
||||||
@@ -150,8 +163,6 @@
|
|||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
TextAlignment="Center"
|
TextAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
IsVisibleChanged="MenuWhenVisibilityChanged"
|
|
||||||
Visibility="{Binding NotMenuEdit}"
|
|
||||||
/>
|
/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
namespace GeekDesk.Control.UserControls.PannelCard
|
namespace GeekDesk.Control.UserControls.PannelCard
|
||||||
@@ -23,6 +24,9 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
private int menuSelectIndexTemp = -1;
|
private int menuSelectIndexTemp = -1;
|
||||||
private AppData appData = MainWindow.appData;
|
private AppData appData = MainWindow.appData;
|
||||||
|
|
||||||
|
//是否正在修改菜单
|
||||||
|
private static bool IS_EDIT = false;
|
||||||
|
|
||||||
public LeftCardControl()
|
public LeftCardControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -77,9 +81,14 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void MenuWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
|
private void MenuWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
TextBlock tb = sender as TextBlock;
|
StackPanel sp = sender as StackPanel;
|
||||||
if (tb.Visibility == Visibility.Collapsed)
|
|
||||||
|
ListBoxItem lbi = (sp.TemplatedParent as ContentPresenter).TemplatedParent as ListBoxItem;
|
||||||
|
if (sp.Visibility == Visibility.Collapsed)
|
||||||
{
|
{
|
||||||
|
SolidColorBrush scb = new SolidColorBrush(Colors.Red);
|
||||||
|
lbi.MouseEnter += Lbi_MouseEnter;
|
||||||
|
|
||||||
if (MenuListBox.SelectedIndex != -1)
|
if (MenuListBox.SelectedIndex != -1)
|
||||||
{
|
{
|
||||||
menuSelectIndexTemp = MenuListBox.SelectedIndex;
|
menuSelectIndexTemp = MenuListBox.SelectedIndex;
|
||||||
@@ -89,9 +98,33 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
{
|
{
|
||||||
MenuListBox.SelectedIndex = menuSelectIndexTemp;
|
MenuListBox.SelectedIndex = menuSelectIndexTemp;
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
SolidColorBrush bac = new SolidColorBrush(Color.FromRgb(236, 236, 236));
|
||||||
|
SolidColorBrush fontColor = new SolidColorBrush(Colors.Black);
|
||||||
|
|
||||||
|
lbi.MouseEnter += (s, me) =>
|
||||||
|
{
|
||||||
|
lbi.Background = bac;
|
||||||
|
};
|
||||||
|
|
||||||
|
lbi.MouseLeave += Lbi_MouseLeave;
|
||||||
|
|
||||||
|
lbi.Selected += (s, me) =>
|
||||||
|
{
|
||||||
|
lbi.MouseLeave -= Lbi_MouseLeave;
|
||||||
|
lbi.Background = bac;
|
||||||
|
lbi.Foreground = fontColor;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Lbi_MouseEnter(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
ListBoxItem lbi = sender as ListBoxItem;
|
||||||
|
lbi.Background = Brushes.Transparent;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新建菜单
|
/// 新建菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -105,6 +138,27 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
|
MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
|
||||||
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
|
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
|
||||||
appData.AppConfig.SelectedMenuIcons = info.IconList;
|
appData.AppConfig.SelectedMenuIcons = info.IconList;
|
||||||
|
|
||||||
|
ItemCollection ic = MenuListBox.Items;
|
||||||
|
SolidColorBrush bac = new SolidColorBrush(Color.FromRgb(236, 236, 236));
|
||||||
|
SolidColorBrush fontColor = new SolidColorBrush(Colors.Black);
|
||||||
|
foreach (var icItem in ic)
|
||||||
|
{
|
||||||
|
ListBoxItem lbi = icItem as ListBoxItem;
|
||||||
|
lbi.MouseEnter += (s, me) =>
|
||||||
|
{
|
||||||
|
lbi.Background = bac;
|
||||||
|
};
|
||||||
|
|
||||||
|
lbi.MouseLeave += Lbi_MouseLeave;
|
||||||
|
|
||||||
|
lbi.Selected += (s, me) =>
|
||||||
|
{
|
||||||
|
lbi.MouseLeave -= Lbi_MouseLeave;
|
||||||
|
lbi.Background = bac;
|
||||||
|
lbi.Foreground = fontColor;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -116,6 +170,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
{
|
{
|
||||||
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
|
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
|
||||||
menuInfo.MenuEdit = (int)Visibility.Visible;
|
menuInfo.MenuEdit = (int)Visibility.Visible;
|
||||||
|
IS_EDIT = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -154,6 +209,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void LostFocusOrEnterDown(object sender, EventArgs e)
|
private void LostFocusOrEnterDown(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
bool done = true;
|
||||||
TextBox menuBox = null;
|
TextBox menuBox = null;
|
||||||
if (e.GetType() == typeof(KeyEventArgs))
|
if (e.GetType() == typeof(KeyEventArgs))
|
||||||
{
|
{
|
||||||
@@ -161,13 +217,17 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
if (eKey.Key == Key.Enter)
|
if (eKey.Key == Key.Enter)
|
||||||
{
|
{
|
||||||
menuBox = ((TextBox)sender);
|
menuBox = ((TextBox)sender);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
done = false;
|
||||||
}
|
}
|
||||||
}
|
} else if (e.GetType() == typeof(RoutedEventArgs))
|
||||||
else if (e.GetType() == typeof(RoutedEventArgs))
|
|
||||||
{
|
{
|
||||||
menuBox = ((TextBox)sender);
|
menuBox = ((TextBox)sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (done)
|
||||||
|
{
|
||||||
if (menuBox != null)
|
if (menuBox != null)
|
||||||
{
|
{
|
||||||
MenuInfo menuInfo = menuBox.Tag as MenuInfo;
|
MenuInfo menuInfo = menuBox.Tag as MenuInfo;
|
||||||
@@ -175,6 +235,9 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
menuInfo.MenuName = text;
|
menuInfo.MenuName = text;
|
||||||
menuInfo.MenuEdit = Visibility.Collapsed;
|
menuInfo.MenuEdit = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
IS_EDIT = false;
|
||||||
|
MenuListBox.SelectedIndex = menuSelectIndexTemp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -185,6 +248,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
private void MenuEditWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
|
private void MenuEditWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
TextBox box = sender as TextBox;
|
TextBox box = sender as TextBox;
|
||||||
|
MenuInfo mi = box.Tag as MenuInfo;
|
||||||
if (box.Visibility == Visibility.Visible)
|
if (box.Visibility == Visibility.Visible)
|
||||||
{
|
{
|
||||||
Keyboard.Focus(box);
|
Keyboard.Focus(box);
|
||||||
@@ -208,7 +272,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
//设置对应菜单的图标列表
|
//设置对应菜单的图标列表
|
||||||
if (MenuListBox.SelectedIndex == -1)
|
if (MenuListBox.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.MenuList.Count - 1].IconList;
|
//appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.MenuList.Count - 1].IconList;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -216,6 +280,20 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ListBoxItem_Unselected(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
//添加Leave效果
|
||||||
|
ListBoxItem lbi = sender as ListBoxItem;
|
||||||
|
lbi.Background = Brushes.Transparent;
|
||||||
|
lbi.MouseLeave += Lbi_MouseLeave;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Lbi_MouseLeave(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
ListBoxItem lbi = sender as ListBoxItem;
|
||||||
|
lbi.Background = Brushes.Transparent;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 鼠标悬停切换菜单
|
/// 鼠标悬停切换菜单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -223,7 +301,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void Menu_MouseEnter(object sender, MouseEventArgs e)
|
private void Menu_MouseEnter(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (appData.AppConfig.HoverMenu)
|
if (appData.AppConfig.HoverMenu && !IS_EDIT)
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
@@ -241,5 +319,6 @@ namespace GeekDesk.Control.UserControls.PannelCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
SizeChanged="Window_SizeChanged"
|
SizeChanged="Window_SizeChanged"
|
||||||
KeyDown="OnKeyDown"
|
KeyDown="OnKeyDown"
|
||||||
Focusable="True"
|
Focusable="True"
|
||||||
|
MouseDown="MainWindow_MouseDown"
|
||||||
>
|
>
|
||||||
<WindowChrome.WindowChrome>
|
<WindowChrome.WindowChrome>
|
||||||
<WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/>
|
<WindowChrome CaptionHeight="0" ResizeBorderThickness="15"/>
|
||||||
@@ -73,6 +74,7 @@
|
|||||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<TextBox x:Name="EmptyTextBox" Width="0"/>
|
||||||
|
|
||||||
<DockPanel Grid.Row="0" Grid.Column="0" MouseMove="DragMove">
|
<DockPanel Grid.Row="0" Grid.Column="0" MouseMove="DragMove">
|
||||||
<DockPanel.Background>
|
<DockPanel.Background>
|
||||||
|
|||||||
@@ -524,7 +524,14 @@ namespace GeekDesk
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 为了让修改菜单的textBox失去焦点
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
EmptyTextBox.Focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ namespace GeekDesk.ViewModel
|
|||||||
private string geometryColor; //几何图标颜色
|
private string geometryColor; //几何图标颜色
|
||||||
private ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
|
private ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[field: NonSerializedAttribute()]
|
[field: NonSerializedAttribute()]
|
||||||
private static string[] NO_WRITE_ARR = new string[] { "IsEdit" };
|
private static string[] NO_WRITE_ARR = new string[] { "IsEdit"};
|
||||||
|
|
||||||
|
|
||||||
public bool IsEdit
|
public bool IsEdit
|
||||||
|
|||||||
Reference in New Issue
Block a user