Ver Fonte

注释 - 文字注释属性面板逻辑

chenrongqian@kdanmobile.com há 2 anos atrás
pai
commit
9c5de09a22

+ 51 - 36
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs

@@ -201,13 +201,15 @@ namespace PDF_Office.CustomControl.CompositeControl
             var isSelectedEmpty = (bool)e.NewValue;
             if(control != null)
             {
-                if(isSelectedEmpty)
-                {
-                    control.comBox.SelectedItem = null;
-                    control.SelectedIndex = -1;
-                    control.SelectedItems = null;
-                    control.title.Text = "";
-                }
+                //弃用:IsSelectedEmpty属性,可用SelectedItems == null来处理下拉框不选中的情况。
+
+                //if(isSelectedEmpty)
+                //{
+                //    control.comBox.SelectedItem = null;
+                //    control.SelectedIndex = -1;
+                //    control.SelectedItems = null;
+                //    control.title.Text = "";
+                //}
             }
         }
         
@@ -216,48 +218,61 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             var control = d as CustomComboControl;
             var selectedItems = (ComboDataItem)e.NewValue;
-            if (control != null & selectedItems != null && control.IsSelectedEmpty == false)
+            if (control != null /* && control.IsSelectedEmpty == false*/)
             {
-                if(control.comBox.Items != null && control.comBox.Items.Count > 0)
+                if(selectedItems != null)
                 {
-                    if(control.IsValueContent)
+                    if (control.comBox.Items != null && control.comBox.Items.Count > 0)
                     {
-                        control.ValueStr = selectedItems.ValueStr;
+                        if (control.IsValueContent)
+                        {
+                            control.ValueStr = selectedItems.ValueStr;
+                        }
+                        else
+                        {
+                            control.Value = selectedItems.Value;
+                        }
                     }
-                    else
+
+                    if (control.comBox.Items == null || control.comBox.Items.Count == 0)
                     {
-                        control.Value = selectedItems.Value;
+                        control.title.Text = selectedItems.Content;
                     }
-                }
+                    else
+                    {
+                        int index = -1;
+                        ComboDataItem temp;
+                        if (control.IsValueContent)
+                            temp = control.Items.FirstOrDefault(inlineItem => inlineItem.ValueStr == selectedItems.ValueStr);
+                        else
+                            temp = control.Items.FirstOrDefault(inlineItem => inlineItem.Value == selectedItems.Value);
 
-                if(control.comBox.Items == null || control.comBox.Items.Count == 0)
-                {
-                    control.title.Text = selectedItems.Content;
-                }
-                else
-                {
-                    int index = -1;
-                    ComboDataItem temp;
-                    if (control.IsValueContent)
-                        temp = control.Items.FirstOrDefault(inlineItem => inlineItem.ValueStr == selectedItems.ValueStr);
-                   else
-                        temp = control.Items.FirstOrDefault(inlineItem => inlineItem.Value == selectedItems.Value);
+                        if (temp != null)
+                            index = control.Items.IndexOf(temp);
 
-                    if (temp != null)
-                        index = control.Items.IndexOf(temp);
 
+                        if (index >= 0)
+                        {
+                            control.SelectedIndex = -1;
+                            control.SelectedIndex = index;
+                        }
+                        else
+                            control.title.Text = selectedItems.Content;
 
-                    if (index >= 0)
-                    {
-                        control.SelectedIndex = -1;
-                        control.SelectedIndex = index;
                     }
-                    else
-                        control.title.Text = selectedItems.Content;
+                }
 
+                else
+                {
+                    control.comBox.SelectedItem = null;
+                    control.SelectedIndex = -1;
+                    control.SelectedItems = null;
+                    control.title.Text = "";
                 }
+              
 
             }
+            
         }
 
         //集合绑定下拉框Itemsource触发属性
@@ -265,7 +280,7 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             var control = d as CustomComboControl;
             var itemsource = (List<ComboDataItem>)e.NewValue;
-            if (control != null && control.IsSelectedEmpty == false)
+            if (control != null /*& control.IsSelectedEmpty == false*/)
             {
                 control.SelectedIndex = -1;
                 control.comBox.ItemsSource = itemsource;
@@ -279,7 +294,7 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             var control = d as CustomComboControl;
             var selectedIndex = (int)e.NewValue;
-            if (control != null && control.IsSelectedEmpty == false)
+            if (control != null /*&& control.IsSelectedEmpty == false*/)
             {
                 if(control.comBox.Items != null && control.comBox.Items.Count > 0 && selectedIndex != -1)
                 {

+ 124 - 183
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -19,67 +19,35 @@ using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 {
-    public class FreetextAnnotPropertyViewModel : FontBoard, INavigationAware
+    public class FreetextAnnotPropertyViewModel : BindableBase, INavigationAware
     {
-        private bool isSelectedEmpty;
-        public bool IsSelectedEmpty
+        private FontBoardVm _fontVm = new FontBoardVm(true);
+        public FontBoardVm FontVm
         {
-            get { return isSelectedEmpty; }
-            set { SetProperty(ref isSelectedEmpty, value); }
+            get { return _fontVm; }
+            set { SetProperty(ref _fontVm, value); }
         }
 
-        private double fillOpacity = 1;
-        public double FillOpacity
+        private AnnotBasePropertyVM _basicVm = new AnnotBasePropertyVM();
+        public AnnotBasePropertyVM BasicVm
         {
-            get { return fillOpacity; }
-            set
-            {
-                SetProperty(ref fillOpacity, value);
-            }
+            get { return _basicVm; }
+            set => SetProperty(ref _basicVm, value);
         }
 
-        private Brush _currentFillColor = new SolidColorBrush(Colors.Transparent);
-        public Brush CurrentFillColor
-        {
-            get { return _currentFillColor; }
-            set
-            {
-                SetProperty(ref _currentFillColor, value);
-            }
-        }
+        public AnnotAttribEvent AnnotEvent { get; set; }
+        private FreeTextAnnotArgs Annot;
+        private AnnotPropertyPanel PropertyPanel;
 
-        private Brush fillColor = new SolidColorBrush(Colors.Transparent);
-        public Brush FillColor
-        {
-            get { return fillColor; }
-            set
-            {
-                SetProperty(ref fillColor, value);
-                if (IsCanSave)
-                {
-                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, (fillColor as SolidColorBrush).Color);
-                    AnnotEvent?.UpdateAnnot();
-                }
-                else
-                {
-                    CurrentFillColor = fillColor;
-                }
-               
-            }
-        }
-
-        private bool _isMultiSelected = false;
-        public bool IsMultiSelected
-        {
-            get { return _isMultiSelected; }
-            set => SetProperty(ref _isMultiSelected, value);
-        }
+        public DelegateCommand SelectedPresetFontCommand { get; set; }
+        public DelegateCommand FontFamilyChangedCommand { get; set; }
+        public DelegateCommand FontStyleWeightChangedCommand { get; set; }
 
         public DelegateCommand<object> SelectedFillOpacityCommand { get; set; }
-        public DelegateCommand<object> SelectedFontStyleCommand { get; set; }
+        
         public DelegateCommand<object> SelectedColorCommand { get; set; }
         public DelegateCommand<object> SelectedFillColorCommand { get; set; }
-        public DelegateCommand<object> FontFamilyChangedCommand { get; set; }
+        
 
         public DelegateCommand<object> FontSizeChangedCommand { get; set; }
         public DelegateCommand<object> TextAlignCheckedCommand { get; set; }
@@ -95,54 +63,44 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public FreetextAnnotPropertyViewModel()
         {
+            //文本设置
+            //预设文本样式
+            SelectedPresetFontCommand = new DelegateCommand(SelectedPresetFont);
+            //文本字重、字体
+            FontStyleWeightChangedCommand = new DelegateCommand(FontStyleWeightChanged);
+            //字体
+            FontFamilyChangedCommand = new DelegateCommand(FontFamilyChanged_Command);
+            //自定义
+            CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
+            //重新定义
+            ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle);
+            //恢复默认
+            RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle);
+
             SelectedFillOpacityCommand = new DelegateCommand<object>(SelectedFillOpacity);
-            SelectedFontStyleCommand = new DelegateCommand<object>(SelectedFontStyle);
+           
             SelectedColorCommand = new DelegateCommand<object>(SelectedColor_Command);
             SelectedFillColorCommand = new DelegateCommand<object>(SelectedFillColor_Command);
-            FontFamilyChangedCommand = new DelegateCommand<object>(FontFamilyChanged_Command);
+            
             FontSizeChangedCommand = new DelegateCommand<object>(FontSizeChanged_Command);
             TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
             LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
             SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
 
-            CustomFontStyleCommand = new DelegateCommand(CustomFontStyle);
-            ReDefineFontStyleCommand = new DelegateCommand(ReDefineFontStyle);
-            RestoreDefaultStyleCommand = new DelegateCommand(RestoreDefaultStyle);
+            
             InitVariable();
         }
 
         private void InitVariable()
         {
-            InitFontStyles();
-            InitFontFamilyComboBox();
-            InitFontStyleComboBox();
+            
         }
 
-        private void InitFontFamilyComboBox()
-        {
-            FontFamilyItems = TextFont.GetFamily();
-        }
-
-        private void InitFontStyleComboBox()
-        {
-            FontStyleItems = TextFont.GetFontStyle();
-        }
-
-        private void InitFontStyles()
-        {
-            PresetFontItems = new List<ComboDataItem>();
-            PresetFontList = TextFont.GetCachePresetFontList();
-
-            foreach (var item in PresetFontList)
-            {
-                ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
-                PresetFontItems.Add(itemData);
-            }
-        }
+     
 
         private void TextAlignChecked(object obj)
         {
-            if ((string)obj != null /*&& TextEditEvent != null*/)
+            if ((string)obj != null)
             {
                 switch ((string)obj)
                 {
@@ -158,7 +116,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                         AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
                         break;
 
-                    case "Align":
+                    case "Justify":
+                        AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
                         break;
                 }
 
@@ -185,39 +144,62 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
         
-        private void SelectedFontStyle(object obj)
+        //从预设样式设置文本
+        private void SelectedPresetFont()
         {
-            if (obj != null && (PresetFontItem)obj != null)
+            if (FontVm.CurrentPresetFont != null)
             {
-                var item = (PresetFontItem)obj;
+                var itemComboxItem = FontVm.CurrentPresetFont;
 
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, item.mFontSize);
+                var item = FontVm.PresetFontList.FirstOrDefault(temp => temp.mTag == itemComboxItem.ValueStr);
+                if (item != null)
+                {
+                    FontVm.GetCurrentFontSize(item.mFontSize);
+                    FontVm.GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
+                    FontVm.GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
+
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontSize, item.mFontSize);
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, item.mFontFamily);
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, item.mFontStyle);
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, item.mFontWeight);
+                    AnnotEvent?.UpdateAnnot();
+                }
+            }
+        }
 
+        //设置文本字重、样式
+        private void FontStyleWeightChanged()
+        {
+            if(FontVm.CurrrentFontWeightStyle != null)
+            {
+                FontVm.UpdateFontWeight_Style();
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontStyle, FontVm.FontWeightItem);
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontWeight, FontVm.FontStyleItem);
                 AnnotEvent?.UpdateAnnot();
-
             }
         }
+        
 
         private void SelectedFillOpacity(object obj)
         {
             if (obj != null)
             {
-                FillOpacity = (double)obj;
-                SelectColor.Opacity = FillOpacity;
+                BasicVm.FillOpacity = (double)obj;
+                BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
 
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
                 AnnotEvent?.UpdateAnnot();
             }
         }
 
         private void SelectedOpacityValue(object obj)
         {
-            if (obj != null)
+            if (obj != null && obj is double)
             {
-                FillOpacity = (double)obj;
-                SelectColor.Opacity = FillOpacity;
+                BasicVm.FillOpacity = (double)obj;
+                BasicVm.FillColor.Opacity = BasicVm.FillOpacity;
 
-                AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, FillOpacity);
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.Transparency, BasicVm.FillOpacity);
                 AnnotEvent?.UpdateAnnot();
             }
         }
@@ -238,9 +220,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             }
         }
 
-        private void FontFamilyChanged_Command(object obj)
+        private void FontFamilyChanged_Command()
         {
-
+            if (string.IsNullOrEmpty(FontVm.CurrentFontFamily.ValueStr) == false)
+            {
+                AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(FontVm.CurrentFontFamily.ValueStr));
+                AnnotEvent?.UpdateAnnot();
+            }
         }
 
         private void SelectedFillColor_Command(object obj)
@@ -251,12 +237,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 if (colorValue != null)
                 {
 
-                    FillColor = new SolidColorBrush(colorValue);
-                    FillColor.Opacity = FillOpacity;
-
-                    Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
-                    changeData[AnnotArgsType.AnnotFreehand] = obj;
-                    PropertyPanel.InvokeToMyTools(this, changeData);
+                    BasicVm.FillColor = new SolidColorBrush(colorValue);
+                    // BasicVm.FillColor.Opacity = BasicVmFillOpacity;
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, colorValue);
+                    AnnotEvent?.UpdateAnnot();
                 }
             }
         }
@@ -268,23 +252,19 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 var colorValue = (Color)obj;
                 if (colorValue != null)
                 {
-
-                    SelectColor = new SolidColorBrush(colorValue);
-                    SelectColor.Opacity = FillOpacity;
-                    
-                    Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
-                    changeData[AnnotArgsType.AnnotFreehand] = obj;
-                    PropertyPanel.InvokeToMyTools(this, changeData);
+                    FontVm.FontColor = new SolidColorBrush(colorValue);
+                    AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, colorValue);
+                    AnnotEvent?.UpdateAnnot();
                 }
             }
         }
 
         private void CustomFontStyle()
         {
-            if (CurrentPresetFont != null)
+            if (FontVm.CurrentPresetFont != null)
             {
                 ContextMenu menu;
-                if (CurrentPresetFont.ValueStr == "custom")
+                if (FontVm.CurrentPresetFont.ValueStr == "custom")
                 {
                     menu = SelectAnnotContextMenu(false);
                 }
@@ -321,14 +301,14 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public List<PresetFontItem> FontStyleList = new List<PresetFontItem>();
         private void ReDefineFontStyle()
         {
-            var item = FontStyleList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
+            var item = FontStyleList.FirstOrDefault(temp => temp.mTag == FontVm.CurrentPresetFont.ValueStr);
 
-            if (CurrentFontFamily.ValueStr == "Bold")
+            if (FontVm.CurrentFontFamily.ValueStr == "Bold")
             {
                 item.mFontStyle = FontStyles.Normal;
                 item.mFontWeight = FontWeights.Bold;
             }
-            else if (CurrentFontFamily.ValueStr == "Regular")
+            else if (FontVm.CurrentFontFamily.ValueStr == "Regular")
             {
                 item.mFontStyle = FontStyles.Normal;
                 item.mFontWeight = FontWeights.Normal;
@@ -339,12 +319,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 item.mFontWeight = FontWeights.Bold;
             }
 
-            item.mFontSize = (int)CurrentFontSize.Value;
+            item.mFontSize = (int)FontVm.CurrentFontSize.Value;
         }
 
         private void RestoreDefaultStyle()
         {
-            var item = FontStyleList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
+           // var item = FontStyleList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
         }
 
         public bool IsNavigationTarget(NavigationContext navigationContext)
@@ -354,14 +334,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
-            IsCanSave = false;
-            ChangedValue -= FontMode_ChangedValue;
-            IsMultiSelected = false;
+            BasicVm.IsMultiSelected = false;
         }
 
-        public AnnotAttribEvent AnnotEvent { get; set; }
-        private FreeTextAnnotArgs Annot;
-        private AnnotPropertyPanel PropertyPanel;
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
             navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
@@ -370,91 +345,57 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 AnnotEvent = PropertyPanel.AnnotEvent;
                 Annot = PropertyPanel.annot as FreeTextAnnotArgs;
                 LoadPropertyHandler?.Invoke(this, Annot);
-                ChangedValue -= FontMode_ChangedValue;
-                ChangedValue += FontMode_ChangedValue;
                 if (PropertyPanel.annotlists != null && PropertyPanel.annotlists.Count > 1)
                 {
-                    IsMultiSelected = true;
+                    BasicVm.IsMultiSelected = true;
                 }
                 else
                 {
-                    IsMultiSelected = false;
+                    BasicVm.IsMultiSelected = false;
                 }
 
-                if(IsMultiSelected)
+                if(BasicVm.IsMultiSelected)
                 {
+                    FontVm.CurrentFontFamily = null;
+                    FontVm.CurrentFontSize = null;
+                    FontVm.CurrrentFontWeightStyle = null;
+                    FontVm.CurrentPresetFont = null;
 
+                    BasicVm.SetStrDashStyle("None");
                 }
                 else
                 {
                     GetAnnotProperty();
                 }
-
-                IsCanSave = true;
             }
         }
 
         private void GetAnnotProperty()
         {
-            SelectColor = new SolidColorBrush(Annot.FontColor);
-            FillColor = new SolidColorBrush(Annot.BgColor);
-
-            GetCurrentFontSize((int)Annot.FontSize);
-            GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
-            GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
-        }
-
-        private void FontMode_ChangedValue(object sender, FontSetModeType e)
-        {
-            if (sender != null)
-            {
-                switch (e)
-                {
-                    case FontSetModeType.PresetFontStyes:
-                        if (PresetFontList != null && sender is string == true)
-                        {
-                            var item = PresetFontList.FirstOrDefault(temp => temp.mTag == (string)sender);
-                            if (item != null && Annot != null)
-                            {
-
-                            }
-                        }
-                        break;
-                    case FontSetModeType.FontFamilys:
-                        if (sender is string == true && IsCanSave)
-                        {
-                            AnnotEvent.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily((string)sender));
-                            AnnotEvent.UpdateAnnot();
-                        }
+            BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
+            BasicVm.FillOpacity = Annot.Transparency;
+
+            FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
+            FontVm.GetCurrentFontSize((int)Annot.FontSize);
+            FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
+            FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
+
+            string str = "";
+            if (Annot.Align == TextAlignment.Left)
+                str = "AlignLeft";
+            else if (Annot.Align == TextAlignment.Center)
+                str = "AlignCenter";
+            else if (Annot.Align == TextAlignment.Right)
+                str = "AlignRight";
+            else if(Annot.Align == TextAlignment.Justify)
+                str = "AlignJustify";
+            else
+                str = "None";
 
-                        break;
-                    case FontSetModeType.FontSizes:
-                        if (sender is double == true && (double)sender > 0 && Annot.FontSize > 0)
-                        {
-                            AnnotEvent.UpdateAttrib(AnnotAttrib.FontSize, (double)sender);
-                            AnnotEvent.UpdateAnnot();
-                        }
+            BasicVm.SetStrDashStyle(str);
 
-                        break;
-                    case FontSetModeType.FontWeight_Style:
-                        UpdateFontWeight_Style();
-                        AnnotEvent.UpdateAttrib(AnnotAttrib.FontWeight, FontWeightItem);
-                        AnnotEvent.UpdateAttrib(AnnotAttrib.FontStyle, FontStyleItem);
-                        AnnotEvent.UpdateAnnot();
-                        break;
-                    case FontSetModeType.FontColor:
-                        if (sender is Color == true)
-                        {
-                            AnnotEvent.UpdateAttrib(AnnotAttrib.FontColor, (SelectColor as SolidColorBrush).Color );
-                            AnnotEvent.UpdateAnnot();
-                        }
+        }
 
-                        break;
 
-                    case FontSetModeType.TextAlignment:
-                        break;
-                }
-            }
-        }
     }
 }

+ 222 - 0
PDF Office/ViewModels/PropertyPanel/FontBoardVM.cs

@@ -306,4 +306,226 @@ namespace PDF_Office.ViewModels.PropertyPanel
 
         #endregion
     }
+
+
+
+
+
+
+    //设置字体大小、字体内容排版、字体颜色、字体样式、字重
+    public class FontBoardVm : BindableBase
+    {
+        #region 变量
+        public List<ComboDataItem> FontFamilyItems { get; protected set; }
+        public List<ComboDataItem> FontStyleItems { get; protected set; }
+        public List<ComboDataItem> PresetFontItems { get; protected set; }
+
+        public List<PresetFontItem> PresetFontList = new List<PresetFontItem>();
+
+        public FontBoardVm(bool isInitdata)
+        {
+            if (isInitdata)
+                InitBaseVariable();
+        }
+        #endregion
+
+        #region 初始化下拉框或列表默认的数据
+        protected void InitBaseVariable()
+        {
+            InitBase_PresetFontStyles();
+            InitBase_FontFamilys();
+            InitBase_FontStyles();
+        }
+
+        //预设字体样式
+        private void InitBase_PresetFontStyles()
+        {
+            PresetFontItems = new List<ComboDataItem>();
+            PresetFontList = TextFont.GetCachePresetFontList();
+
+            foreach (var item in PresetFontList)
+            {
+                ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
+                PresetFontItems.Add(itemData);
+            }
+
+        }
+        //字体
+        private void InitBase_FontFamilys()
+        {
+            FontFamilyItems = TextFont.GetFamily();
+        }
+        //字重
+        private void InitBase_FontStyles()
+        {
+            FontStyleItems = TextFont.GetFontStyle();
+        }
+
+        #endregion
+
+        #region 属性
+
+        private ComboDataItem _currentPresetFont = new ComboDataItem("Custom", "Custom");
+        public ComboDataItem CurrentPresetFont
+        {
+            get { return _currentPresetFont; }
+            set => SetProperty(ref _currentPresetFont, value);
+        }
+
+        #region 字体样式
+
+        //下拉框列表
+        private ComboDataItem _currentFontFamily = new ComboDataItem("Helvetica", "Helvetica");
+        public ComboDataItem CurrentFontFamily
+        {
+            get { return _currentFontFamily; }
+            set => SetProperty(ref _currentFontFamily, value);
+        }
+        #endregion
+
+        #region 字体大小
+        //下拉框列表:字体大小
+        private ComboDataItem _currentFontSize = new ComboDataItem(6);
+        public ComboDataItem CurrentFontSize
+        {
+            get { return _currentFontSize; }
+            set => SetProperty(ref _currentFontSize, value);
+        }
+
+        #endregion
+
+
+        //FontStyle & FontWeight
+
+        private FontStyle _fontStyleItem;
+        public FontStyle FontStyleItem
+        {
+            get { return _fontStyleItem; }
+            set { SetProperty(ref _fontStyleItem, value); }
+        }
+
+        private FontWeight _fontWeight;
+        public FontWeight FontWeightItem
+        {
+            get { return _fontWeight; }
+            set { SetProperty(ref _fontWeight, value); }
+        }
+
+        private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular");
+        public ComboDataItem CurrrentFontWeightStyle
+        {
+            get { return _currrentFontWeightStyle; }
+            set => SetProperty(ref _currrentFontWeightStyle, value);
+        }
+
+        public void UpdateFontWeight_Style()
+        {
+            switch (CurrrentFontWeightStyle.ValueStr)
+            {
+                case "Regular":
+                    FontStyleItem = FontStyles.Normal;
+                    FontWeightItem = FontWeights.Normal;
+                    break;
+
+                case "Bold":
+                    FontStyleItem = FontStyles.Normal;
+                    FontWeightItem = FontWeights.Bold;
+                    break;
+
+                case "Italic":
+                    FontStyleItem = FontStyles.Italic;
+                    FontWeightItem = FontWeights.Normal;
+                    break;
+
+                case "Bold Italic":
+                    FontStyleItem = FontStyles.Italic;
+                    FontWeightItem = FontWeights.Bold;
+                    break;
+            }
+        }
+
+        private C_TEXT_ALIGNMENT _textAlignment;
+        public C_TEXT_ALIGNMENT TextAlignmentItem
+        {
+            get { return _textAlignment; }
+            set { SetProperty(ref _textAlignment, value); }
+        }
+
+        //颜色
+        private Brush _fontColor = new SolidColorBrush(Colors.Black);
+        public Brush FontColor
+        {
+            get { return _fontColor; }
+            set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; }
+        }
+
+        private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
+        public Brush CurrentFontColor
+        {
+            get { return _currentFontColor; }
+            set => SetProperty(ref _currentFontColor, value);
+        }
+
+        //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中
+        public string strAglinState{ get; private set; }
+        //VM赋值
+        public void SetStrAglinState(string str)
+        {
+            strAglinState = str;
+        }
+        #endregion
+
+
+        #region 列表选中赋值
+
+        public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights)
+        {
+            string strValue = "";
+            string strContent = "";
+            if (fontStyle == FontStyles.Normal)
+            {
+                if (fontWeights == FontWeights.Normal)
+                {
+                    strValue = "Regular";
+                    strContent = "常规";
+                }
+
+                else
+                {
+                    strValue = "Bold";
+                    strContent = "粗体";
+                }
+
+            }
+            else
+            {
+                if (fontWeights == FontWeights.Normal)
+                {
+                    strValue = "Italic";
+                    strContent = "斜体";
+                }
+                else
+                {
+                    strValue = "Bold Italic";
+                    strContent = "粗斜体";
+                }
+
+            }
+
+            CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent);
+        }
+
+
+        public void GetCurrentFontSize(int size)
+        {
+            CurrentFontSize = new ComboDataItem(size);
+        }
+
+        public void GetCurrentFontFamily(string fontFamily, string uiStr)
+        {
+            CurrentFontFamily = new ComboDataItem(fontFamily, uiStr);
+        }
+
+        #endregion
+    }
 }

+ 40 - 23
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml

@@ -53,18 +53,18 @@
         <StackPanel>
             <TextBlock Name="AnnotTypeTitle" FontFamily="Segoe UI Semibold" FontWeight="SemiBold" FontSize="18" LineHeight="24" HorizontalAlignment="Left" Margin="10,8,0,0">Freetext</TextBlock>
             <Border Width="228" Height="100" BorderThickness="1" CornerRadius="2" BorderBrush="#DDDDDD" Background="White" Margin="0,8,0,0"
-                     Visibility="{Binding IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"
+                     Visibility="{Binding BasicVm.IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"
                     >
                 <Grid>
                     <Border Name="FreeTextBorder" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="5"
-                            Opacity="{Binding FillOpacity}"
-                            Background="{Binding FillColor}">
+                            Opacity="{Binding BasicVm.FillOpacity}"
+                            Background="{Binding BasicVm.FillColor}">
                         <TextBlock Name="SampleText"
-                                   Foreground="{Binding SelectColor}" 
-                                   FontFamily="{Binding  CurrentFontFamily.ValueStr}"
-                                   FontWeight="{Binding FontWeightItem}" 
-                                   FontStyle="{Binding FontStyleItem}"
-                                   FontSize="{Binding CurrentFontSize.Value}" Opacity="{Binding FillOpacity}"
+                                   Foreground="{Binding FontVm.FontColor}" 
+                                   FontFamily="{Binding  FontVm.CurrentFontFamily.ValueStr}"
+                                   FontWeight="{Binding FontVm.FontWeightItem}" 
+                                   FontStyle="{Binding FontVm.FontStyleItem}"
+                                   FontSize="{Binding FontVm.CurrentFontSize.Value}" Opacity="{Binding BasicVm.FillOpacity}"
                                    Text="Sample" HorizontalAlignment="Center" VerticalAlignment="Center">
                         </TextBlock>
                     </Border>
@@ -96,13 +96,19 @@
                         <ColumnDefinition Width="auto"/>
                     </Grid.ColumnDefinitions>
                     <CompositeControl:CustomComboControl
-                            x:Name="FontTitleBox"
+                            x:Name="ComBoxPresetFont"
                             Width="188"
                             Height="32"
                             HorizontalAlignment="Left"
                             IsValueContent="True"
-                            ItemSource="{Binding PresetFontItems}"
-                            SelectedItems="{Binding CurrentPresetFont, Mode=TwoWay}" />
+                            ItemSource="{Binding FontVm.PresetFontItems,Mode=OneWay}"
+                            SelectedItems="{Binding FontVm.CurrentPresetFont, Mode=TwoWay}">
+                        <i:Interaction.Triggers>
+                            <i:EventTrigger EventName="ValueChanged">
+                                <i:InvokeCommandAction Command="{Binding SelectedPresetFontCommand}"/>
+                            </i:EventTrigger>
+                        </i:Interaction.Triggers>
+                    </CompositeControl:CustomComboControl>
 
 
                     <Button Grid.Column="1"
@@ -130,9 +136,14 @@
                             x:Name="FontFamilyBox"
                             Height="32"
                             IsValueContent="True"
-                            ItemSource="{Binding FontFamilyItems}"
-                            IsSelectedEmpty ="{Binding IsSelectedEmpty}"
-                            SelectedItems="{Binding CurrentFontFamily, Mode=TwoWay}" />
+                            ItemSource="{Binding FontVm.FontFamilyItems,Mode=OneWay}"
+                            SelectedItems="{Binding FontVm.CurrentFontFamily, Mode=TwoWay}" >
+                        <i:Interaction.Triggers>
+                            <i:EventTrigger EventName="ValueChanged">
+                                <i:InvokeCommandAction Command="{Binding FontFamilyChangedCommand}"/>
+                            </i:EventTrigger>
+                        </i:Interaction.Triggers>
+                    </CompositeControl:CustomComboControl>
 
                     <Grid Margin="0,8">
                         <CompositeControl:CustomComboControl
@@ -141,9 +152,14 @@
                                 Height="32"
                                 HorizontalAlignment="Left"
                                 IsValueContent="True"
-                                ItemSource="{Binding FontStyleItems}"
-                                IsSelectedEmpty ="{Binding IsSelectedEmpty}"
-                                SelectedItems="{Binding CurrrentFontWeightStyle, Mode=TwoWay}" />
+                                ItemSource="{Binding FontVm.FontStyleItems}"
+                                SelectedItems="{Binding FontVm.CurrrentFontWeightStyle, Mode=TwoWay}">
+                            <i:Interaction.Triggers>
+                                <i:EventTrigger EventName="ValueChanged">
+                                    <i:InvokeCommandAction Command="{Binding FontFamilyChangedCommand}"/>
+                                </i:EventTrigger>
+                            </i:Interaction.Triggers>
+                        </CompositeControl:CustomComboControl>
 
 
                         <CompositeControl:CustomComboControl
@@ -151,8 +167,7 @@
                                 Width="110"
                                 Height="32"
                                 HorizontalAlignment="Right"
-                                IsSelectedEmpty ="{Binding IsSelectedEmpty}"
-                                SelectedItems="{Binding CurrentFontSize, Mode=TwoWay}" />
+                                SelectedItems="{Binding FontVm.CurrentFontSize, Mode=TwoWay}" />
                     </Grid>
                     <Grid>
                         <StackPanel Orientation="Horizontal">
@@ -315,7 +330,7 @@
                                     Foreground="#616469"
                                     GroupName="TextAlign"
                                     Style="{DynamicResource GreyBgRadioBtnStyle}"
-                                    Tag="Align">
+                                    Tag="Justify">
                                 <RadioButton.Content>
                                     <Grid Width="32" Height="32">
                                         <Canvas Margin="5,10,0,0">
@@ -358,7 +373,7 @@
                                 Width="56"
                                 HorizontalAlignment="Right"
                                 ShowColorList="Collapsed"  
-                                UIColor="{Binding CurrentFontColor,Mode=OneWay}"
+                                UIColor="{Binding FontVm.CurrentFontColor,Mode=OneWay}"
                             >
                             <i:Interaction.Triggers>
                                 <i:EventTrigger EventName="SelectedColorInvoke">
@@ -376,7 +391,8 @@
                 </Grid.RowDefinitions>
                 <TextBlock Text="Fill" VerticalAlignment="Center"/>
                 <CompositeControl:SlidContent x:Name="layerThick" HorizontalAlignment="Right"
-                    Visibility="{Binding IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"                           
+                                              InitValue="{Binding BasicVm.FillOpacity,Mode=OneWay}"
+                    Visibility="{Binding BasicVm.IsMultiSelected,Converter={StaticResource InvertBoolToVisibleConvert}}"                           
                                               >
                     <i:Interaction.Triggers>
                         <i:EventTrigger EventName="SelectedValueChanged">
@@ -384,7 +400,8 @@
                         </i:EventTrigger>
                     </i:Interaction.Triggers>
                 </CompositeControl:SlidContent>
-                <CompositeControl:ColorContent Grid.Row="1" x:Name="cusColor" UIColor="{Binding CurrentFillColor,Mode=OneWay}">
+                <CompositeControl:ColorContent Grid.Row="1" x:Name="cusColor"
+                                               UIColor="{Binding BasicVm.CurrentFillColor,Mode=OneWay}">
                     <i:Interaction.Triggers>
                         <i:EventTrigger EventName="SelectedColorInvoke">
                             <i:InvokeCommandAction Command="{Binding SelectedFillColorCommand}" CommandParameter="{Binding ElementName=cusColor,Path=SelectedColor}"/>

+ 34 - 7
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml.cs

@@ -23,7 +23,7 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
     /// </summary>
     public partial class FreetextAnnotProperty : UserControl
     {
-      
+        private FreetextAnnotPropertyViewModel ViewModel => DataContext as FreetextAnnotPropertyViewModel;
         public FreetextAnnotProperty()
         {
             InitializeComponent();
@@ -35,11 +35,38 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
 
         private void usercontrol_Loaded(object sender, RoutedEventArgs e)
         {
-            FontFamilyBox.SelectedIndex = 0;
-            FontStyleBox.SelectedIndex = 0;
-            FontSizeBox.SelectedIndex = 0;
-            ThicknessBox.SelectedIndex = 0;
+            //FontFamilyBox.SelectedIndex = 0;
+            //FontStyleBox.SelectedIndex = 0;
+            //FontSizeBox.SelectedIndex = 0;
+            //ThicknessBox.SelectedIndex = 0;
             BindingEvent();
+            if(ViewModel != null && string.IsNullOrEmpty(ViewModel.BasicVm.strDashStyle) == false)
+            {
+                var str = ViewModel.BasicVm.strDashStyle;
+                if (str == "AlignLeft")
+                {
+                    TextAlignLeftBtn.IsChecked = true;
+                }
+                else if(str == "AlignCenter")
+                {
+                    TextAlignCenterBtn.IsChecked = true;
+                }
+                else if (str == "AlignRight")
+                {
+                    TextAlignRightBtn.IsChecked = true;
+                }
+                else if (str == "AlignJustify")
+                {
+                    TextAlignBtn.IsChecked = true;
+                }
+                else
+                {
+                    TextAlignLeftBtn.IsChecked = false;
+                    TextAlignCenterBtn.IsChecked = false;
+                    TextAlignRightBtn.IsChecked = false;
+                    TextAlignBtn.IsChecked = false;
+                }
+            }
         }
 
         private void usercontrol_Unloaded(object sender, RoutedEventArgs e)
@@ -50,12 +77,12 @@ namespace PDF_Office.Views.PropertyPanel.AnnotPanel
         private void BindingEvent()
         {
             UnBindingEvent();
-            ThicknessBox.SelectionChanged += ThicknessBox_SelectionChanged;
+            //ThicknessBox.SelectionChanged += ThicknessBox_SelectionChanged;
         }
 
         private void UnBindingEvent()
         {
-            ThicknessBox.SelectionChanged -= ThicknessBox_SelectionChanged;
+           // ThicknessBox.SelectionChanged -= ThicknessBox_SelectionChanged;
         }
 
         private void ThicknessBox_SelectionChanged(object sender, SelectionChangedEventArgs e)