Browse Source

自定义下拉框 - 下拉框都不选中的状态

chenrongqian@kdanmobile.com 2 năm trước cách đây
mục cha
commit
1254992890

+ 34 - 5
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs

@@ -164,6 +164,17 @@ namespace PDF_Office.CustomControl.CompositeControl
             set { SetValue(SelectedItemsProperty, value); }
         }
 
+        //外部需要下拉框都不选中时,true为不选中,false为正常选中
+        public bool IsSelectedEmpty
+        {
+            get { return (bool)GetValue(IsSelectedEmptyProperty); }
+            set { SetValue(IsSelectedEmptyProperty, value); }
+        }
+
+        public static readonly DependencyProperty IsSelectedEmptyProperty =
+    DependencyProperty.Register("IsSelectedEmpty", typeof(bool), typeof(CustomComboControl), new PropertyMetadata(false, IsSelectedEmptyPropertyChanged));
+
+
         public static readonly DependencyProperty SelectedItemsProperty =
          DependencyProperty.Register("SelectedItems", typeof(ComboDataItem), typeof(CustomComboControl), new PropertyMetadata(null, SelectedItemsPropertyChanged));
 
@@ -184,11 +195,28 @@ namespace PDF_Office.CustomControl.CompositeControl
           DependencyProperty.Register("IsValueContent", typeof(bool), typeof(CustomComboControl), new PropertyMetadata(false));
 
         //集合绑定下拉框 SelectedItems触发属性
+        private static void IsSelectedEmptyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var control = d as CustomComboControl;
+            var isSelectedEmpty = (bool)e.NewValue;
+            if(control != null)
+            {
+                if(isSelectedEmpty)
+                {
+                    control.comBox.SelectedItem = null;
+                    control.SelectedIndex = -1;
+                    control.SelectedItems = null;
+                    control.title.Text = "";
+                }
+            }
+        }
+        
+
         private static void SelectedItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
             var control = d as CustomComboControl;
             var selectedItems = (ComboDataItem)e.NewValue;
-            if (control != null & selectedItems != null)
+            if (control != null & selectedItems != null && control.IsSelectedEmpty == false)
             {
                 if(control.comBox.Items != null && control.comBox.Items.Count > 0)
                 {
@@ -237,7 +265,7 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             var control = d as CustomComboControl;
             var itemsource = (List<ComboDataItem>)e.NewValue;
-            if (control != null)
+            if (control != null && control.IsSelectedEmpty == false)
             {
                 control.SelectedIndex = -1;
                 control.comBox.ItemsSource = itemsource;
@@ -251,12 +279,12 @@ namespace PDF_Office.CustomControl.CompositeControl
         {
             var control = d as CustomComboControl;
             var selectedIndex = (int)e.NewValue;
-            if (control != null)
+            if (control != null && control.IsSelectedEmpty == false)
             {
                 if(control.comBox.Items != null && control.comBox.Items.Count > 0 && selectedIndex != -1)
                 {
                     control.comBox.SelectedIndex = selectedIndex;
-                    if (control.comBox.SelectedItem != null)
+                    if (control.comBox.SelectedItem != null )
                         control.SelectedItems = (ComboDataItem)control.comBox.SelectedItem;
                     else
                         control.SelectedItems = null;
@@ -273,7 +301,8 @@ namespace PDF_Office.CustomControl.CompositeControl
             }
             else
             {
-                title.Text = Items[SelectedIndex].Content;
+                if (IsSelectedEmpty == false)
+                    title.Text = Items[SelectedIndex].Content;
             }
         }
     }

+ 3 - 3
PDF Office/ViewModels/PropertyPanel/FontSetModeVM.cs

@@ -116,7 +116,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
             {
                 bool isChange = IsEqualComboData(_fontSizeData, value);
 
-                if(value.Value > 0)
+                if(isChange && value.Value > 0)
                 SetProperty(ref _fontSizeData, value);
 
                 if (isChange && value.Value > 0)
@@ -151,7 +151,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
             get { return _fontWeightStyleItem; }
             set
             {
-                bool isChange = IsEqualStrComboData(_presetTextData, value);
+                bool isChange = IsEqualStrComboData(_fontWeightStyleItem, value);
                 SetProperty(ref _fontWeightStyleItem, value);
                 if (isChange)
                 {
@@ -234,7 +234,7 @@ namespace PDF_Office.ViewModels.PropertyPanel
         }
         private bool IsEqualStrComboData(ComboDataItem oldValue, ComboDataItem newValue)
         {
-            if (newValue == null && string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false)
+            if (newValue == null || string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false)
                 return false;
 
             if (oldValue != null && newValue != null)

+ 1 - 1
PDF Office/ViewModels/PropertyPanel/PDFEdit/ImageEditPropertyViewModel.cs

@@ -358,7 +358,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
             var tranUI = (TextEditEvent.Transparent / 255.0)*100;
             var temp = Math.Round((double)tranUI, 0);
             Transpent = temp;
-
+            OpacityUI = temp/100.0;
 
         }
         //点击空白处时

+ 32 - 7
PDF Office/ViewModels/PropertyPanel/PDFEdit/TextEditPropertyViewModel.cs

@@ -24,7 +24,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
     public class TextEditPropertyViewModel : PDFEditVM, INavigationAware
     {
         #region
-         
+        private bool isSelectedEmpty;
+        public bool IsSelectedEmpty
+        {
+            get { return isSelectedEmpty; }
+            set { SetProperty(ref isSelectedEmpty, value); }
+        }
         private ComPDFKit.PDFPage.Edit.TextAlignType _textAlign;
         public ComPDFKit.PDFPage.Edit.TextAlignType TextAlign
         {
@@ -420,6 +425,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
                 {
                     TextEditEvent = TextEditEventList[0];
                     GetPDFEdit();
+                    if (TextEditEventList.Count > 1)
+                        IsSelectedEmpty = true;
+                    else
+                        IsSelectedEmpty = false;
 
                     if (TextEditEventList.Count == 2)
                     {
@@ -458,11 +467,26 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
                             var item = FontStyleList.FirstOrDefault(temp => temp.mTag == (string)sender);
                             if (item != null && TextEditEvent != null)
                             {
-                                TextEditEvent.FontFamily = item.mFontFamily;
-                                TextEditEvent.FontSize = item.mFontSize;
-                                TextEditEvent.FontWeight = item.mFontWeight;
-                                TextEditEvent.FontStyle = item.mFontStyle;
-                                TextEditEvent.UpdatePDFEditByEventArgs();
+                                if(TextEditEventList.Count == 1 && IsSelectedEmpty == false)
+                                {
+                                    TextEditEvent.FontFamily = item.mFontFamily;
+                                    TextEditEvent.FontSize = item.mFontSize;
+                                    TextEditEvent.FontWeight = item.mFontWeight;
+                                    TextEditEvent.FontStyle = item.mFontStyle;
+                                    TextEditEvent.UpdatePDFEditByEventArgs();
+                                }
+                                else
+                                {
+                                    foreach (var itemlist in TextEditEventList)
+                                    {
+                                        itemlist.FontFamily = item.mFontFamily;
+                                        itemlist.FontSize = item.mFontSize;
+                                        itemlist.FontWeight = item.mFontWeight;
+                                        itemlist.FontStyle = item.mFontStyle;
+                                        itemlist.UpdatePDFEditByEventArgs();
+                                    }
+                                }
+                                
                             }
                         }
                         break;
@@ -512,7 +536,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
 
         private void  GetPDFEdit()
         {
-            if (TextEditEvent != null)
+            if (TextEditEvent != null && TextEditEventList.Count == 1)
             {
                 SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
                 FontSizeData = new ComboDataItem(TextEditEvent.FontSize);
@@ -533,6 +557,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.PDFEdit
         {
             IsCanSave = false;
             TextEditEvent = null;
+            IsSelectedEmpty = false;
             ClearCheckedAglin?.Invoke(null, null);
             PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
             ChangedValue -= FontMode_ChangedValue;

+ 4 - 0
PDF Office/Views/PropertyPanel/PDFEdit/TextEditProperty.xaml

@@ -125,6 +125,7 @@
                             Height="32"
                             HorizontalAlignment="Left"
                             IsValueContent="True"
+                            IsSelectedEmpty ="{Binding IsSelectedEmpty}"
                             ItemSource="{Binding PresetTextItems}"
                             SelectedItems="{Binding PresetTextData, Mode=TwoWay}" />
 
@@ -153,6 +154,7 @@
                             x:Name="FontFamilyBox"
                             Height="32"
                             IsValueContent="True"
+                            IsSelectedEmpty ="{Binding IsSelectedEmpty}"
                             ItemSource="{Binding FontFamilyItems}"
                             SelectedItems="{Binding FontFamilyData, Mode=TwoWay}" />
 
@@ -163,6 +165,7 @@
                                 Height="32"
                                 HorizontalAlignment="Left"
                                 IsValueContent="True"
+                                IsSelectedEmpty ="{Binding IsSelectedEmpty}"
                                 ItemSource="{Binding FontStyleItems}"
                                 SelectedItems="{Binding FontWeightStyleItem, Mode=TwoWay}" />
 
@@ -172,6 +175,7 @@
                                 Width="110"
                                 Height="32"
                                 HorizontalAlignment="Right"
+                                IsSelectedEmpty ="{Binding IsSelectedEmpty}"
                                 SelectedItems="{Binding FontSizeData, Mode=TwoWay}" />
                         </Grid>
                         <Grid>