diff --git a/Control/UserControls/PannelCard/LeftCardControl.xaml b/Control/UserControls/PannelCard/LeftCardControl.xaml
index 1f6d242..911b851 100644
--- a/Control/UserControls/PannelCard/LeftCardControl.xaml
+++ b/Control/UserControls/PannelCard/LeftCardControl.xaml
@@ -22,6 +22,7 @@
+
@@ -42,24 +43,34 @@
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
@@ -87,14 +98,14 @@
+ Padding="2,3,0,2"
+ ItemsSource="{Binding MenuList}"
+ Tag="{Binding AppConfig.MenuCardWidth}"
+ BorderThickness="0" Foreground="{x:Null}"
+ SelectedIndex="{Binding AppConfig.SelectedMenuIndex}"
+ VirtualizingPanel.VirtualizationMode="Recycling"
+ SelectionChanged="Menu_SelectionChanged"
+ >
@@ -123,36 +134,36 @@
-
+ HorizontalAlignment="Left"
+ Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}, ConverterParameter=35}"
+ FontSize="16"
+ Height="28"
+ VerticalAlignment="Center"
+ TextAlignment="Left"
+ LostFocus="LostFocusOrEnterDown"
+ KeyDown="LostFocusOrEnterDown"
+ Tag="{Binding}"
+ Padding="2"
+ BorderThickness="0"
+ IsVisibleChanged="MenuEditWhenVisibilityChanged"
+ Visibility="{Binding MenuEdit}"/>
+
+ BorderThickness="0"
+ hc:IconElement.Geometry="{Binding MenuGeometry}"
+ hc:IconElement.Height="18"
+ hc:IconElement.Width="18"
+ IsEnabled="False"
+ Opacity="1"
+ Foreground="{Binding GeometryColor}"
+ />
+ HorizontalAlignment="Center"
+ TextAlignment="Center"
+ VerticalAlignment="Center"
+ />
diff --git a/Control/UserControls/PannelCard/LeftCardControl.xaml.cs b/Control/UserControls/PannelCard/LeftCardControl.xaml.cs
index 840810e..cb54329 100644
--- a/Control/UserControls/PannelCard/LeftCardControl.xaml.cs
+++ b/Control/UserControls/PannelCard/LeftCardControl.xaml.cs
@@ -11,6 +11,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
+using System.Windows.Media;
using System.Windows.Threading;
namespace GeekDesk.Control.UserControls.PannelCard
@@ -23,6 +24,9 @@ namespace GeekDesk.Control.UserControls.PannelCard
private int menuSelectIndexTemp = -1;
private AppData appData = MainWindow.appData;
+ //是否正在修改菜单
+ private static bool IS_EDIT = false;
+
public LeftCardControl()
{
InitializeComponent();
@@ -77,9 +81,14 @@ namespace GeekDesk.Control.UserControls.PannelCard
///
private void MenuWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
{
- TextBlock tb = sender as TextBlock;
- if (tb.Visibility == Visibility.Collapsed)
+ StackPanel sp = sender as StackPanel;
+
+ 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)
{
menuSelectIndexTemp = MenuListBox.SelectedIndex;
@@ -89,9 +98,33 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
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;
+ }
+
///
/// 新建菜单
///
@@ -105,6 +138,27 @@ namespace GeekDesk.Control.UserControls.PannelCard
MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
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;
+ };
+ }
}
///
@@ -116,6 +170,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
menuInfo.MenuEdit = (int)Visibility.Visible;
+ IS_EDIT = true;
}
///
@@ -154,6 +209,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
///
private void LostFocusOrEnterDown(object sender, EventArgs e)
{
+ bool done = true;
TextBox menuBox = null;
if (e.GetType() == typeof(KeyEventArgs))
{
@@ -161,19 +217,26 @@ namespace GeekDesk.Control.UserControls.PannelCard
if (eKey.Key == Key.Enter)
{
menuBox = ((TextBox)sender);
+ } else
+ {
+ done = false;
}
- }
- else if (e.GetType() == typeof(RoutedEventArgs))
+ } else if (e.GetType() == typeof(RoutedEventArgs))
{
menuBox = ((TextBox)sender);
}
- if (menuBox != null)
+ if (done)
{
- MenuInfo menuInfo = menuBox.Tag as MenuInfo;
- string text = menuBox.Text;
- menuInfo.MenuName = text;
- menuInfo.MenuEdit = Visibility.Collapsed;
+ if (menuBox != null)
+ {
+ MenuInfo menuInfo = menuBox.Tag as MenuInfo;
+ string text = menuBox.Text;
+ menuInfo.MenuName = text;
+ menuInfo.MenuEdit = Visibility.Collapsed;
+ }
+ IS_EDIT = false;
+ MenuListBox.SelectedIndex = menuSelectIndexTemp;
}
}
@@ -185,6 +248,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
private void MenuEditWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
{
TextBox box = sender as TextBox;
+ MenuInfo mi = box.Tag as MenuInfo;
if (box.Visibility == Visibility.Visible)
{
Keyboard.Focus(box);
@@ -208,7 +272,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
//设置对应菜单的图标列表
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
{
@@ -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;
+ }
+
///
/// 鼠标悬停切换菜单
///
@@ -223,7 +301,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
///
private void Menu_MouseEnter(object sender, MouseEventArgs e)
{
- if (appData.AppConfig.HoverMenu)
+ if (appData.AppConfig.HoverMenu && !IS_EDIT)
{
new Thread(() =>
{
@@ -241,5 +319,6 @@ namespace GeekDesk.Control.UserControls.PannelCard
}
}
+
}
}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 060869d..0a8aed8 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -22,6 +22,7 @@
SizeChanged="Window_SizeChanged"
KeyDown="OnKeyDown"
Focusable="True"
+ MouseDown="MainWindow_MouseDown"
>
@@ -73,6 +74,7 @@
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index e662964..e9ceca4 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -524,7 +524,14 @@ namespace GeekDesk
}
}
-
-
+ ///
+ /// 为了让修改菜单的textBox失去焦点
+ ///
+ ///
+ ///
+ private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
+ {
+ EmptyTextBox.Focus();
+ }
}
}
diff --git a/ViewModel/MenuInfo.cs b/ViewModel/MenuInfo.cs
index 71812ae..e8c4d6b 100644
--- a/ViewModel/MenuInfo.cs
+++ b/ViewModel/MenuInfo.cs
@@ -24,8 +24,10 @@ namespace GeekDesk.ViewModel
private string geometryColor; //几何图标颜色
private ObservableCollection iconList = new ObservableCollection();
+
+
[field: NonSerializedAttribute()]
- private static string[] NO_WRITE_ARR = new string[] { "IsEdit" };
+ private static string[] NO_WRITE_ARR = new string[] { "IsEdit"};
public bool IsEdit