From ff2a1036826618b181715fd21b080f8741b1ec83 Mon Sep 17 00:00:00 2001 From: liufei Date: Thu, 20 Jan 2022 15:47:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=AE=E6=94=B9=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=90=8D=E6=97=B6=E7=9A=84=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModel/MenuInfo.cs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/ViewModel/MenuInfo.cs b/ViewModel/MenuInfo.cs index 2db5812..c12d28f 100644 --- a/ViewModel/MenuInfo.cs +++ b/ViewModel/MenuInfo.cs @@ -1,6 +1,8 @@ using GeekDesk.Constant; using GeekDesk.Util; +using Newtonsoft.Json; using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; @@ -11,17 +13,33 @@ namespace GeekDesk.ViewModel [Serializable] public class MenuInfo : INotifyPropertyChanged { - + private string menuName; private string menuId; private Visibility menuEdit = Visibility.Collapsed; private Visibility notMenuEdit = Visibility.Visible; + private bool isEdit = false; private string menuGeometry; //菜单几何图标 private string geometryColor; //几何图标颜色 private ObservableCollection iconList = new ObservableCollection(); + [field: NonSerializedAttribute()] + private string[] NO_WRITE_ARR = new string[] { "IsEdit" }; + + public bool IsEdit + { + get + { + return isEdit; + } + set + { + isEdit = value; + OnPropertyChanged("IsEdit"); + } + } public string MenuGeometry { get @@ -65,7 +83,7 @@ namespace GeekDesk.ViewModel set { menuName = value; - OnPropertyChanged("MenuName"); + OnPropertyChanged("MenuName"); } } @@ -93,9 +111,12 @@ namespace GeekDesk.ViewModel menuEdit = value; if (menuEdit == Visibility.Visible) { + IsEdit = true; NotMenuEdit = Visibility.Collapsed; - } else + } + else { + IsEdit = false; NotMenuEdit = Visibility.Visible; } OnPropertyChanged("MenuEdit"); @@ -128,12 +149,24 @@ namespace GeekDesk.ViewModel } } + public override String ToString() + { + return JsonConvert.SerializeObject(this); + } + [field: NonSerializedAttribute()] public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + foreach (var field in NO_WRITE_ARR) + { + if (field.Equals(propertyName)) + { + return; + } + } CommonCode.SaveAppData(MainWindow.appData); } } -} +} \ No newline at end of file