This commit is contained in:
liufei
2021-05-08 17:27:41 +08:00
parent 5f38782623
commit 876e78bbfc
12 changed files with 570 additions and 110 deletions

View File

@@ -7,6 +7,8 @@ namespace GeekDesk.Constant
{
WINDOW_WIDTH = 650, //默认窗体宽度
WINDOW_HEIGHT = 700, //默认窗体高度
MENU_CARD_WIDHT = 150 //默认菜单栏宽度
MENU_CARD_WIDHT = 150, //默认菜单栏宽度
IMAGE_WIDTH = 60, //默认图标宽度
IMAGE_HEIGHT = 60, //默认图标高度
}
}

View File

@@ -0,0 +1,135 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
namespace GeekDesk.EditTextBlock
{
public class EditableTextBlock : TextBlock
{
public bool IsInEditMode
{
get
{
return (bool)GetValue(IsInEditModeProperty);
}
set
{
SetValue(IsInEditModeProperty, value);
}
}
private EditableTextBlockAdorner _adorner;
// Using a DependencyProperty as the backing store for IsInEditMode. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsInEditModeProperty =
DependencyProperty.Register("IsInEditMode", typeof(bool), typeof(EditableTextBlock), new UIPropertyMetadata(false, IsInEditModeUpdate));
/// <summary>
/// Determines whether [is in edit mode update] [the specified obj].
/// </summary>
/// <param name="obj">The obj.</param>
/// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
private static void IsInEditModeUpdate(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
EditableTextBlock textBlock = obj as EditableTextBlock;
if (null != textBlock)
{
//Get the adorner layer of the uielement (here TextBlock)
AdornerLayer layer = AdornerLayer.GetAdornerLayer(textBlock);
//If the IsInEditMode set to true means the user has enabled the edit mode then
//add the adorner to the adorner layer of the TextBlock.
if (textBlock.IsInEditMode)
{
if (null == textBlock._adorner)
{
textBlock._adorner = new EditableTextBlockAdorner(textBlock);
//Events wired to exit edit mode when the user presses Enter key or leaves the control.
textBlock._adorner.TextBoxKeyUp += textBlock.TextBoxKeyUp;
textBlock._adorner.TextBoxLostFocus += textBlock.TextBoxLostFocus;
}
layer.Add(textBlock._adorner);
}
else
{
//Remove the adorner from the adorner layer.
Adorner[] adorners = layer.GetAdorners(textBlock);
if (adorners != null)
{
foreach (Adorner adorner in adorners)
{
if (adorner is EditableTextBlockAdorner)
{
layer.Remove(adorner);
}
}
}
//Update the textblock's text binding.
BindingExpression expression = textBlock.GetBindingExpression(TextProperty);
if (null != expression)
{
expression.UpdateTarget();
}
}
}
}
/// <summary>
/// Gets or sets the length of the max.
/// </summary>
/// <value>The length of the max.</value>
public int MaxLength
{
get
{
return (int)GetValue(MaxLengthProperty);
}
set
{
SetValue(MaxLengthProperty, value);
}
}
// Using a DependencyProperty as the backing store for MaxLength. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MaxLengthProperty =
DependencyProperty.Register("MaxLength", typeof(int), typeof(EditableTextBlock), new UIPropertyMetadata(0));
private void TextBoxLostFocus(object sender, RoutedEventArgs e)
{
IsInEditMode = false;
}
/// <summary>
/// release the edit mode when user presses enter.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs"/> instance containing the event data.</param>
private void TextBoxKeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
IsInEditMode = false;
}
}
/// <summary>
/// Invoked when an unhandled <see cref="E:System.Windows.Input.Mouse.MouseDown"/> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs"/> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param>
protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (e.MiddleButton == MouseButtonState.Pressed)
{
IsInEditMode = true;
}
else if (e.ClickCount == 2)
{
IsInEditMode = true;
}
}
}
}

View File

@@ -0,0 +1,101 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace GeekDesk.EditTextBlock
{
/// <summary>
/// Adorner class which shows textbox over the text block when the Edit mode is on.
/// </summary>
public class EditableTextBlockAdorner : Adorner
{
private readonly VisualCollection _collection;
private readonly TextBox _textBox;
private readonly TextBlock _textBlock;
public EditableTextBlockAdorner(EditableTextBlock adornedElement)
: base(adornedElement)
{
_collection = new VisualCollection(this);
_textBox = new TextBox();
_textBlock = adornedElement;
Binding binding = new Binding("Text") { Source = adornedElement };
_textBox.SetBinding(TextBox.TextProperty, binding);
_textBox.AcceptsReturn = true;
_textBox.MaxLength = adornedElement.MaxLength;
_textBox.KeyUp += _textBox_KeyUp;
_collection.Add(_textBox);
}
void _textBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
_textBox.Text = _textBox.Text.Replace("\r\n", string.Empty);
BindingExpression expression = _textBox.GetBindingExpression(TextBox.TextProperty);
if (null != expression)
{
expression.UpdateSource();
}
}
}
protected override Visual GetVisualChild(int index)
{
return _collection[index];
}
protected override int VisualChildrenCount
{
get
{
return _collection.Count;
}
}
protected override Size ArrangeOverride(Size finalSize)
{
_textBox.Arrange(new Rect(0, 0, _textBlock.DesiredSize.Width + 50, _textBlock.DesiredSize.Height * 1.5));
_textBox.Focus();
return finalSize;
}
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext.DrawRectangle(null, new Pen
{
Brush = Brushes.Gold,
Thickness = 2
}, new Rect(0, 0, _textBlock.DesiredSize.Width + 50, _textBlock.DesiredSize.Height * 1.5));
}
public event RoutedEventHandler TextBoxLostFocus
{
add
{
_textBox.LostFocus += value;
}
remove
{
_textBox.LostFocus -= value;
}
}
public event KeyEventHandler TextBoxKeyUp
{
add
{
_textBox.KeyUp += value;
}
remove
{
_textBox.KeyUp -= value;
}
}
}
}

View File

@@ -90,6 +90,8 @@
<Compile Include="Constant\SortType.cs" />
<Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.cs" />
<Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.Drag.cs" />
<Compile Include="EditTextBlock\EditableTextBlock.cs" />
<Compile Include="EditTextBlock\EditableTextBlockAdorner.cs" />
<Compile Include="Util\CommonCode.cs" />
<Compile Include="Util\ConsoleManager.cs" />
<Compile Include="Util\DragAdorner.cs" />
@@ -98,10 +100,11 @@
<Compile Include="Util\MenuWidthConvert.cs" />
<Compile Include="Util\MouseUtilities.cs" />
<Compile Include="Util\SystemIcon.cs" />
<Compile Include="Util\VisibilityConvert.cs" />
<Compile Include="ViewModel\AppConfig.cs" />
<Compile Include="ViewModel\AppData.cs" />
<Compile Include="ViewModel\IconInfo.cs" />
<Compile Include="ViewModel\MenuViewModel.cs" />
<Compile Include="ViewModel\MenuInfo.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View File

@@ -4,6 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GeekDesk"
xmlns:tp="clr-namespace:GeekDesk.EditTextBlock"
mc:Ignorable="d"
xmlns:util="clr-namespace:GeekDesk.Util"
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window"
@@ -11,8 +12,7 @@
Title="MainWindow" Height="500" Width="600">
<Window.Resources>
<Style x:Key="ListBoxStyle" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
<Style TargetType="{x:Type ListBoxItem}" x:Key="memuStory" BasedOn="{StaticResource ListBoxStyle}">
<Style TargetType="{x:Type TextBlock}" x:Key="memuStory">
<Style.Triggers>
<!--鼠标移入-->
<EventTrigger RoutedEvent="MouseMove">
@@ -39,6 +39,7 @@
<!--左侧栏样式动画-->
<Style x:Key="menuStyle" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItemBaseStyle}">
<Setter Property="FontSize" Value="15"/>
<Setter Property="Margin" Value="0,0,0,1"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform/>
@@ -67,15 +68,31 @@
</Style.Triggers>
</Style>
<BeginStoryboard x:Key="imageStoryboard">
<Storyboard>
<DoubleAnimation To="80" Duration="0:0:0.1" Storyboard.TargetProperty="Width"/>
<DoubleAnimation To="80" Duration="0:0:0.1" Storyboard.TargetProperty="Height"/>
</Storyboard>
</BeginStoryboard>
<!--右侧栏样式动画-->
<Style x:Key="imageStyle" TargetType="Image">
<Setter Property="Width" Value="60"/>
<Setter Property="Height" Value="60"/>
<Setter Property="Source" Value="{Binding BitmapImage}"/>
<Style.Triggers>
<MultiTrigger>
<!--<DataTrigger Binding="{Binding ElementName=sv, Path=ComputedVerticalScrollBarVisibility}" Value="Visible">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation To="80" Duration="0:0:0.1" Storyboard.TargetProperty="Width"/>
<DoubleAnimation To="80" Duration="0:0:0.1" Storyboard.TargetProperty="Height"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>-->
<!--<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
<Condition Property="{Binding RelativeSource={RelativeSource Mode=PreviousData}, Path=IsMouseOver}" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
@@ -93,12 +110,12 @@
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
</Style.Triggers>
</MultiTrigger>-->
</Style>
<util:MenuWidthConvert x:Key="MenuWidthConvert"/>
<util:VisibilityConvert x:Key="VisibilityConvert"/>
</Window.Resources>
@@ -127,28 +144,18 @@
Effect="{DynamicResource EffectShadow2}"
Margin="5,5,0,5"
>
<!--<hc:Card.ContextMenu>
<hc:Card.ContextMenu>
<ContextMenu Width="200">
<TextBlock Text="新建菜单"/>
<MenuItem Header="新建菜单" Click="CreateMenu"/>
</ContextMenu>
</hc:Card.ContextMenu>-->
<!--<ListBox x:Name="menu" BorderThickness="0" ItemsSource="{Binding}" Margin="10,8,10,8"
>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding menu}" FontSize="15" Style="{StaticResource memuStory}" PreviewMouseLeftButtonDown="menuClick" RenderTransformOrigin="0.5,0.5">
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>-->
</hc:Card.ContextMenu>
<ListBox x:Name="menus" ItemsSource="{Binding MenuList}">
<ListBox.Resources>
<ContextMenu x:Key="menuDialog" Width="200">
<MenuItem Header="新建菜单"/>
<MenuItem Header="重命名"/>
<MenuItem Header="删除" Click="deleteMenu"/>
<MenuItem Header="新建菜单" Click="CreateMenu"/>
<MenuItem Header="重命名" Click="RenameMenu" Tag="{Binding}"/>
<MenuItem Header="删除" Click="DeleteMenu" Tag="{Binding}"/>
</ContextMenu>
</ListBox.Resources>
@@ -165,7 +172,24 @@
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" PreviewMouseLeftButtonDown="menuClick" />
<StackPanel>
<TextBox Text="{Binding Path=MenuName, Mode=TwoWay}"
HorizontalAlignment="Left"
Width="{Binding ElementName=leftColumn, Path=Width, Converter={StaticResource MenuWidthConvert}}"
FontSize="15"
TextAlignment="Left"
BorderBrush="{x:Null}"
BorderThickness="0"
LostFocus="LostFocusOrEnterDown"
KeyDown="LostFocusOrEnterDown"
Tag="{Binding}"
IsVisibleChanged="MenuEditWhenVisibilityChanged"
Visibility="{Binding Path=MenuEdit, Converter={StaticResource VisibilityConvert}}"/>
<TextBlock Text="{Binding MenuName}"
PreviewMouseLeftButtonDown="menuClick"
IsVisibleChanged="MenuWhenVisibilityChanged"
Visibility="{Binding Path=NotMenuEdit, Converter={StaticResource VisibilityConvert}}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
@@ -189,7 +213,6 @@
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="5,5,5,5" CornerRadius="10">
<StackPanel Tag="{Binding}"
MouseLeftButtonDown="dataClick"
HorizontalAlignment="Center"
@@ -199,11 +222,17 @@
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
hc:Poptip.Content="{Binding Content}"
hc:Poptip.Placement="BottomLeft"
MouseMove="StackPanel_MouseMove"
>
<Image Style="{StaticResource imageStyle}"></Image>
<Image x:Name="testImage" Style="{StaticResource imageStyle}"></Image>
<TextBlock Width="80" TextWrapping="Wrap" TextAlignment="Center" Height="35" LineHeight="15" FontSize="12" Text="{Binding Name}"/>
</StackPanel>
</Border>
<!--<StackPanel.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource TemplatedParent}}" Value="True">
</DataTrigger>
</StackPanel.Triggers>-->
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

View File

@@ -1,9 +1,11 @@
using DraggAnimatedPanelExample;
using GalaSoft.MvvmLight;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
@@ -19,7 +21,8 @@ namespace GeekDesk
public partial class MainWindow : Window
{
private static AppData appData = CommonCode.GetAppData();
private AppData appData = CommonCode.GetAppDataByFile();
private int menuSelectIndexTemp = -1;
public MainWindow()
{
InitializeComponent();
@@ -40,19 +43,20 @@ namespace GeekDesk
private void loadData()
{
this.DataContext = appData;
appData.MenuList.Add("Test1");
//menus.ItemsSource = appData.MenuList;
appData.MenuList.Add(new MenuInfo() { MenuName = "test1", MenuId = "1", MenuEdit = (int)Visibility.Collapsed });
this.Width = appData.AppConfig.WindowWidth;
this.Height = appData.AppConfig.WindowHeight;
List<IconInfo> iconList;
ObservableCollection<IconInfo> iconList;
if (appData.IconMap.ContainsKey("1"))
{
iconList = appData.IconMap["1"];
}
else
{
iconList = new List<IconInfo>();
iconList = new ObservableCollection<IconInfo>();
appData.IconMap.Add("1", iconList);
}
icons.ItemsSource = iconList;
@@ -89,6 +93,8 @@ namespace GeekDesk
}
}
DelegateCommand<int[]> _swap2;
public DelegateCommand<int[]> SwapCommand2
{
get
@@ -99,18 +105,22 @@ namespace GeekDesk
{
int fromS = indexes[0];
int to = indexes[1];
var elementSource = menus.Items[to];
var dragged = menus.Items[fromS];
ObservableCollection<MenuInfo> menuList = appData.MenuList;
var elementSource = menuList[to];
var dragged = menuList[fromS];
if (fromS > to)
{
menus.Items.Remove(dragged);
menus.Items.Insert(to, dragged);
menuList.Remove(dragged);
menuList.Insert(to, dragged);
}
else
{
menus.Items.Remove(dragged);
menus.Items.Insert(to, dragged);
menuList.Remove(dragged);
menuList.Insert(to, dragged);
}
appData.MenuList = menuList;
//menus.Items.Refresh();
}
);
return _swap2;
@@ -134,14 +144,14 @@ namespace GeekDesk
iconInfo.Path = path;
iconInfo.BitmapImage = bi;
iconInfo.Name = Path.GetFileNameWithoutExtension(path);
List<IconInfo> iconList;
ObservableCollection<IconInfo> iconList;
if (appData.IconMap.ContainsKey("1"))
{
iconList = appData.IconMap["1"];
}
else
{
iconList = new List<IconInfo>();
iconList = new ObservableCollection<IconInfo>();
appData.IconMap.Add("1", iconList);
}
iconList.Add(iconInfo);
@@ -231,44 +241,119 @@ namespace GeekDesk
}
private void deleteMenu(object sender, RoutedEventArgs e)
/// <summary>
/// 删除菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteMenu(object sender, RoutedEventArgs e)
{
//if (data.SelectedIndex == -1)
//{
// return;
//}
ViewModel.Menu pojo = (ViewModel.Menu)((ContextMenu)((MenuItem)sender).Parent).DataContext;
string menuTitle = pojo.menu;
int index = 0;
foreach (object obj in menus.Items)
{
string test = ((ViewModel.Menu)obj).menu;
if (test == menuTitle)
{
menus.Items.RemoveAt(index);
menus.Items.Refresh();
return;
}
index++;
}
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
appData.MenuList.Remove(menuInfo);
CommonCode.SaveAppData(appData);
}
private void StackPanel_MouseMove(object sender, MouseEventArgs e)
{
UIElementCollection childs = ((StackPanel)sender).Children;
IEnumerator iEnumerator = childs.GetEnumerator();
//((Image)iEnumerator.Current).Style;
}
/// <summary>
/// 重命名菜单 将textbox 设置为可见
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RenameMenu(object sender, RoutedEventArgs e)
{
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
menuInfo.MenuEdit = (int)Visibility.Visible;
}
/// <summary>
/// 编辑菜单失焦或者敲下Enter键时保存修改后的菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LostFocusOrEnterDown(object sender, EventArgs e)
{
TextBox menuBox = null;
if (e.GetType() == typeof(KeyEventArgs))
{
KeyEventArgs eKey = e as KeyEventArgs;
if (eKey.Key == Key.Enter)
{
menuBox = ((TextBox)sender);
}
} else if(e.GetType() == typeof(RoutedEventArgs))
{
menuBox = ((TextBox)sender);
}
if (menuBox != null)
{
MenuInfo menuInfo = menuBox.Tag as MenuInfo;
string text = menuBox.Text;
menuInfo.MenuName = text;
menuInfo.MenuEdit = (int)Visibility.Collapsed;
CommonCode.SaveAppData(appData);
}
}
/// <summary>
/// 当修改菜单元素可见时 设置全选并获得焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuEditWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
{
TextBox box = sender as TextBox;
if (box.Visibility == Visibility.Visible)
{
Keyboard.Focus(box);
box.SelectAll();
}
}
/// <summary>
/// 当修改菜单元素可见时 设置原菜单为不可见 并且不可选中
/// 修改菜单元素不可见时 原菜单可见 并 选中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
{
TextBlock tb = sender as TextBlock;
if (tb.Visibility == Visibility.Collapsed)
{
if (menus.SelectedIndex != -1)
{
menuSelectIndexTemp = menus.SelectedIndex;
menus.SelectedIndex = -1;
} else
{
menus.SelectedIndex = menuSelectIndexTemp;
}
}
}
/// <summary>
/// 新建菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CreateMenu(object sender, RoutedEventArgs e)
{
appData.MenuList.Add(new MenuInfo() { MenuEdit = (int)Visibility.Collapsed, MenuId = "zz", MenuName = "NewGouop" });
menus.SelectedIndex = appData.MenuList.Count - 1;
//appData.MenuList[appData.MenuList.Count - 1].MenuEdit = (int)Visibility.Visible;
CommonCode.SaveAppData(appData);
}
}
public class MainModel : ViewModelBase
{
public List<ViewModel.Menu> MenuList { get; set; }
public List<ViewModel.IconInfo> DataList { get; set; }
}
}

View File

@@ -15,7 +15,7 @@ namespace GeekDesk.Util
/// 获取app 数据
/// </summary>
/// <returns></returns>
public static AppData GetAppData()
public static AppData GetAppDataByFile()
{
AppData appData;
if (!File.Exists(AppConstant.DATA_FILE_PATH))

33
Util/VisibilityConvert.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace GeekDesk.Util
{
class VisibilityConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int v = (int)value;
if (v == (int)Visibility.Visible)
{
return Visibility.Visible;
} else if (v == (int)Visibility.Collapsed)
{
return Visibility.Collapsed;
}
return v;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace GeekDesk.ViewModel
@@ -7,11 +8,11 @@ namespace GeekDesk.ViewModel
[Serializable]
class AppData : INotifyPropertyChanged
{
private List<string> menuList = new List<string>();
private Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
private ObservableCollection<MenuInfo> menuList = new ObservableCollection<MenuInfo>();
private Dictionary<string, ObservableCollection<IconInfo>> iconMap = new Dictionary<string, ObservableCollection<IconInfo>>();
private AppConfig appConfig = new AppConfig();
public List<string> MenuList
public ObservableCollection<MenuInfo> MenuList
{
get
{
@@ -24,7 +25,7 @@ namespace GeekDesk.ViewModel
}
}
public Dictionary<string, List<IconInfo>> IconMap
public Dictionary<string, ObservableCollection<IconInfo>> IconMap
{
get
{

View File

@@ -1,4 +1,5 @@
using System;
using GeekDesk.Constant;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Media.Imaging;
@@ -15,6 +16,8 @@ namespace GeekDesk.ViewModel
private BitmapImage bitmapImage; //位图
private byte[] imageByteArr; //图片 base64
private string content; //显示信息
private int imageWidth = (int)DefaultConstant.IMAGE_WIDTH;
private int imageHeight = (int)DefaultConstant.IMAGE_HEIGHT;
public int Count
{
@@ -100,6 +103,19 @@ namespace GeekDesk.ViewModel
}
}
public int ImageWidth
{
get
{
return imageWidth;
}
set
{
imageWidth = value;
OnPropertyChanged("ImageWidth");
}
}
[field: NonSerializedAttribute()]

86
ViewModel/MenuInfo.cs Normal file
View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace GeekDesk.ViewModel
{
[Serializable]
class MenuInfo : INotifyPropertyChanged
{
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string menuName;
private string menuId;
private int menuEdit = (int)Visibility.Collapsed;
private int notMenuEdit = (int)Visibility.Visible;
public string MenuName
{
get
{
return menuName;
}
set
{
menuName = value;
OnPropertyChanged("MenuName");
}
}
public string MenuId
{
get
{
return menuId;
}
set
{
menuId = value;
OnPropertyChanged("MenuId");
}
}
public int MenuEdit
{
get
{
return menuEdit;
}
set
{
menuEdit = value;
if (menuEdit == (int)Visibility.Visible)
{
NotMenuEdit = (int)Visibility.Collapsed;
} else
{
NotMenuEdit = (int)Visibility.Visible;
}
OnPropertyChanged("MenuEdit");
}
}
public int NotMenuEdit
{
get
{
return notMenuEdit;
}
set
{
notMenuEdit = value;
OnPropertyChanged("NotMenuEdit");
}
}
}
}

View File

@@ -1,31 +0,0 @@
using System.Collections.ObjectModel;
namespace GeekDesk.ViewModel
{
class MenuViewModel
{
public MenuViewModel()
{
}
public ObservableCollection<Menu> GetMenus()
{
ObservableCollection<Menu> menus = new ObservableCollection<Menu>();
menus.Add(new Menu() { menu = "test1" });
menus.Add(new Menu() { menu = "test2" });
menus.Add(new Menu() { menu = "test3" });
return menus;
}
}
public class Menu
{
public string menu { get; set; }
}
}