Browse Source

compdfkit(win) - binding 左右侧边栏按钮

liuaoran 1 year ago
parent
commit
a860ac00c6

+ 48 - 13
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -15,6 +15,7 @@ using System.Windows;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
 using System.Windows.Media.Imaging;
+using Compdfkit_Tools.Helper;
 
 namespace Compdfkit_Tools.PDFControl
 {
@@ -24,6 +25,10 @@ namespace Compdfkit_Tools.PDFControl
         private bool isFirstLoad = true;
         public PDFViewControl PdfViewControl;
         public CPDFAnnotationControl PDFAnnotationControl = null;
+        private CPDFDisplaySettingsControl displaySettingsControl = null;
+
+        private PanelState panelState = PanelState.GetInstance();
+
         private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
 
         public event PropertyChangedEventHandler PropertyChanged;
@@ -79,26 +84,51 @@ namespace Compdfkit_Tools.PDFControl
             DataContext = this;
             PDFAnnotationControl = new CPDFAnnotationControl();
             CPDFAnnotationType[] annotationProperties =
-{
+            {
                     CPDFAnnotationType.Highlight, CPDFAnnotationType.Underline, CPDFAnnotationType.Strikeout,
                     CPDFAnnotationType.Squiggly, CPDFAnnotationType.Freehand, CPDFAnnotationType.FreeText,
                     CPDFAnnotationType.Note, CPDFAnnotationType.Circle, CPDFAnnotationType.Square,
                     CPDFAnnotationType.Arrow, CPDFAnnotationType.Line, CPDFAnnotationType.Image,
                     CPDFAnnotationType.Stamp, CPDFAnnotationType.Signature, CPDFAnnotationType.Link,
                     CPDFAnnotationType.Audio
-                };
+            };
             AnnotationBarControl.InitAnnotationBar(annotationProperties);
+
         }
 
+        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
+            {
+                ExpandLeftPanel(panelState.IsLeftPanelExpand);
+            }
+            else if (e.PropertyName == nameof(PanelState.RightPanel))
+            {
+                if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
+                {
+                    ExpandRightPropertyPanel(PDFAnnotationControl, Visibility.Visible);
+                }
+                else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
+                {
+                    ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
+                }
+                else
+                {
+                    ExpandRightPropertyPanel(null, Visibility.Collapsed);
+
+                }
+            }
+        }
 
         #region Init PDFViewer
         public void InitWithPDFViewer(CPDFViewer pdfViewer)
         {
             PdfViewControl.PDFView = pdfViewer;
-
             PDFGrid.Child = PdfViewControl;
-
             FloatPageTool.InitWithPDFViewer(pdfViewer);
+
+            panelState.PropertyChanged += PanelState_PropertyChanged;
+
             DataContext = this;
         }
 
@@ -107,6 +137,11 @@ namespace Compdfkit_Tools.PDFControl
             this.BotaContainer.Child = botaControl;
         }
 
+        public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
+        {
+            this.displaySettingsControl = displaySettingsControl;
+        }
+
         public void ClearAllToolState()
         {
             this.AnnotationBarControl.ClearAllToolState();
@@ -126,15 +161,15 @@ namespace Compdfkit_Tools.PDFControl
         }
 
         private void AnnotationBarControl_Loaded(object sender, RoutedEventArgs e)
-        { 
-                AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
-                AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel; 
+        {
+            AnnotationBarControl.AnnotationPropertyChanged += AnnotationBarControl_AnnotationPropertyChanged;
+            AnnotationBarControl.AnnotationCancel += AnnotationBarControl_AnnotationCancel;
         }
 
         private void AnnotationBarControl_Unloaded(object sender, RoutedEventArgs e)
         {
             AnnotationBarControl.AnnotationPropertyChanged -= AnnotationBarControl_AnnotationPropertyChanged;
-            AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel; 
+            AnnotationBarControl.AnnotationCancel -= AnnotationBarControl_AnnotationCancel;
 
         }
 
@@ -164,6 +199,7 @@ namespace Compdfkit_Tools.PDFControl
         {
             PdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
             PdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
         }
 
         private void PdfAnnotationControl_ClearAnnotationBar(object sender, EventArgs e)
@@ -171,7 +207,7 @@ namespace Compdfkit_Tools.PDFControl
             AnnotationBarControl.ClearAllToolState();
         }
 
-        public void SetViewSettings(Visibility visibility ,CPDFDisplaySettingsControl displaySettingsControl = null)
+        public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
         {
             this.PropertyContainer.Child = displaySettingsControl;
             this.PropertyContainer.Visibility = visibility;
@@ -184,7 +220,7 @@ namespace Compdfkit_Tools.PDFControl
         {
             PropertyContainer.Width = 260;
             PropertyContainer.Child = propertytPanel;
-            PropertyContainer.Visibility = visible; 
+            PropertyContainer.Visibility = visible;
         }
 
         public void ExpandLeftPanel(bool isExpand)
@@ -619,8 +655,6 @@ namespace Compdfkit_Tools.PDFControl
         {
             PDFAnnotationControl.AnnotationCancel();
             ExpandRightPropertyPanel(null, Visibility.Collapsed);
-            //AnnotationBarBtn.IsChecked = false;
-            //ViewSettingBtn.IsChecked = false;
         }
 
         private void AnnotationBarControl_AnnotationPropertyChanged(object sender, CPDFAnnotationType e)
@@ -654,11 +688,12 @@ namespace Compdfkit_Tools.PDFControl
             }
         }
         #endregion
-        
+
         public void ClearViewerControl()
         {
             PDFGrid.Child = null;
             BotaContainer.Child = null;
+            PropertyContainer.Child= null;
         }
     }
 }

+ 83 - 0
Demo/Examples/Compdfkit_Tools/Common/Helper/CommonHelper.cs

@@ -3,8 +3,10 @@ using ComPDFKit.PDFDocument;
 using Microsoft.Win32;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.IO;
 using System.Reflection;
+using System.Runtime.CompilerServices;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
@@ -755,4 +757,85 @@ namespace Compdfkit_Tools.Helper
             }
         }
     }
+
+    public class PanelState
+    {
+        private static PanelState instance;
+
+        public enum RightPanelState
+        {
+            None,
+            PropertyPanel,
+            ViewSettings
+        }
+
+        private bool _isLeftPanelExpand;
+        public bool IsLeftPanelExpand
+        {
+            get { return _isLeftPanelExpand; }
+            set
+            {
+                if (_isLeftPanelExpand != value)
+                {
+                    _isLeftPanelExpand = value;
+                    OnPropertyChanged();
+                }
+            }
+        }
+
+        private RightPanelState _rightPanel;
+        public RightPanelState RightPanel
+        {
+            get { return _rightPanel; }
+            set
+            {
+                if (_rightPanel != value)
+                {
+                    _rightPanel = value;
+                    OnPropertyChanged();
+                }
+            }
+        }
+
+        private PanelState() { }
+
+        public static PanelState GetInstance()
+        {
+            if (instance == null)
+            {
+                instance = new PanelState();
+            }
+            return instance;
+        }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+    }
+
+    public class SaveHelper
+    {
+        private static SaveHelper instance;
+        private bool _canSave;
+        public bool CanSave
+        {
+            get { return _canSave; }
+            set
+            {
+                if (_canSave != value)
+                {
+                    _canSave = value;
+                    OnPropertyChanged();
+                }
+            }
+        }
+
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+    }
 }

+ 43 - 13
Demo/Examples/Compdfkit_Tools/Form/FormControl/FormControl.xaml.cs

@@ -16,12 +16,10 @@ using System.Windows.Navigation;
 using System.Windows.Shapes;
 using ComPDFKitViewer;
 using ComPDFKitViewer.AnnotEvent;
+using Compdfkit_Tools.Helper;
 
 namespace Compdfkit_Tools.PDFControl
 {
-    /// <summary>
-    /// FormControl.xaml 的交互逻辑
-    /// </summary>
     public partial class FormControl : UserControl
     {
         #region Property
@@ -30,6 +28,10 @@ namespace Compdfkit_Tools.PDFControl
         public FromPropertyControl FromPropertyControl = new FromPropertyControl();
         private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
         public event PropertyChangedEventHandler PropertyChanged;
+        private CPDFDisplaySettingsControl displaySettingsControl;
+
+        private PanelState panelState = PanelState.GetInstance();
+
         public bool CanUndo
         {
             get
@@ -80,21 +82,51 @@ namespace Compdfkit_Tools.PDFControl
             DataContext = this;
         }
 
+        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
+            {
+                ExpandLeftPanel(panelState.IsLeftPanelExpand);
+            }
+            else if (e.PropertyName == nameof(PanelState.RightPanel))
+            {
+                if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
+                {
+                    ExpandRightPropertyPanel(FromPropertyControl, Visibility.Visible);
+                }
+                else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
+                {
+                    ExpandRightPropertyPanel(displaySettingsControl, Visibility.Visible);
+                }
+                else
+                {
+                    ExpandRightPropertyPanel(null, Visibility.Collapsed); 
+                }
+            }
+        }
+
         #region Init PDFViewer
 
         public void InitWithPDFViewer(CPDFViewer pdfViewer)
         {
-            PdfViewControl.PDFView = pdfViewer; 
+            PdfViewControl.PDFView = pdfViewer;
             PDFFormTool.InitWithPDFViewer(pdfViewer, FromPropertyControl);
             FloatPageTool.InitWithPDFViewer(pdfViewer);
             PDFGrid.Child = PdfViewControl;
+
+            panelState.PropertyChanged += PanelState_PropertyChanged; 
             DataContext = this;
         }
-        
+
         public void SetBOTAContainer(CPDFBOTABarControl botaControl)
         {
             this.BotaContainer.Child = botaControl;
         }
+        
+        public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
+        {
+            this.displaySettingsControl = displaySettingsControl;
+        }
 
         public void ClearAllToolState()
         {
@@ -120,25 +152,21 @@ namespace Compdfkit_Tools.PDFControl
 
         #region Form
 
-        public void SetViewSettings(Visibility visibility ,CPDFDisplaySettingsControl displaySettingsControl = null)
+        public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
         {
             this.PropertyContainer.Child = displaySettingsControl;
             this.PropertyContainer.Visibility = visibility;
         }
 
         #endregion
-        
+
         #region Expand and collapse Panel
 
         public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
         {
             PropertyContainer.Width = 260;
             PropertyContainer.Child = propertytPanel;
-            PropertyContainer.Visibility = visible;
-            if (visible == Visibility.Collapsed || visible == Visibility.Hidden)
-            {
-                //RightPanelButton.IsChecked = false;
-            }
+            PropertyContainer.Visibility = visible; 
         }
 
         public void ExpandLeftPanel(bool isExpand)
@@ -159,7 +187,7 @@ namespace Compdfkit_Tools.PDFControl
 
         #endregion
 
-                #region Event handle
+        #region Event handle
         private void PDFView_WidgetClickHandler(object sender, WidgetArgs e)
         {
             if (e is WidgetSignArgs)
@@ -278,12 +306,14 @@ namespace Compdfkit_Tools.PDFControl
             PdfViewControl.PDFView.AnnotEditHandler -= PDFView_AnnotEditHandler;
             PdfViewControl.PDFView.AnnotActiveHandler -= PDFView_AnnotActiveHandler;
             PdfViewControl.PDFView.WidgetClickHandler -= PDFView_WidgetClickHandler;
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
         }
 
         public void ClearViewerControl()
         {
             PDFGrid.Child = null;
             BotaContainer.Child = null;
+            PropertyContainer.Child = null;
         }
     }
 }

+ 1 - 2
Demo/Examples/ContentEditorViewControl/MainWindow.xaml

@@ -218,7 +218,7 @@
             </Grid>
         </Grid>
         <Border Name="PopupBorder" Background="#A0000000" Visibility="Collapsed">
-            <Grid> 
+            <Grid>
                 <Grid Name="FileInfoUI"  Width="422" Height="680" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White" Visibility="Collapsed">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="*"></ColumnDefinition>
@@ -244,7 +244,6 @@
 
                 <cpdfcommon:PasswordDialog x:Name="PasswordUI" Visibility="Collapsed"></cpdfcommon:PasswordDialog>
             </Grid>
-
         </Border>
     </Grid>
 </Window>

+ 5 - 20
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -483,10 +483,7 @@ namespace PDFViewer
                             fitWidthMenu.Header = "Automatically Resize";
                             fitWidthMenu.Click += (o, p) =>
                             {
-                                if (pdfViewControl != null)
-                                {
-                                    pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
-                                }
+                                pdfViewControl?.PDFView?.ChangeFitMode(FitMode.FitWidth);
                             };
 
                             e.PopupMenu.Items.Add(fitWidthMenu);
@@ -495,10 +492,7 @@ namespace PDFViewer
                             fitSizeMenu.Header = "Actual Size";
                             fitSizeMenu.Click += (o, p) =>
                             {
-                                if (pdfViewControl != null)
-                                {
-                                    pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
-                                }
+                                pdfViewControl?.PDFView?.ChangeFitMode(FitMode.FitSize);
                             };
 
                             e.PopupMenu.Items.Add(fitSizeMenu);
@@ -534,10 +528,7 @@ namespace PDFViewer
                             singleView.Header = "Single Page";
                             singleView.Click += (o, p) =>
                             {
-                                if (pdfViewControl != null)
-                                {
-                                    pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
-                                }
+                                pdfViewControl?.PDFView?.ChangeViewMode(ViewMode.Single);
                             };
 
                             e.PopupMenu.Items.Add(singleView);
@@ -570,10 +561,7 @@ namespace PDFViewer
                             doubleContinuousView.Header = "Two Pages Continuous";
                             doubleContinuousView.Click += (o, p) =>
                             {
-                                if (pdfViewControl != null)
-                                {
-                                    pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
-                                }
+                                pdfViewControl?.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
                             };
 
                             e.PopupMenu.Items.Add(doubleContinuousView);
@@ -1702,10 +1690,7 @@ namespace PDFViewer
 
                 pdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
                 pdfViewControl.PDFView.SetSplitMode(SplitMode.None);
-                if (displayPanel != null)
-                {
-                    displayPanel.SetVisibilityWhenContentEdit(Visibility.Collapsed);
-                }
+                displayPanel?.SetVisibilityWhenContentEdit(Visibility.Collapsed);
             }
 
             /*

+ 9 - 8
Demo/Examples/PDFViewer_new/MainPage.xaml

@@ -79,7 +79,7 @@
                         </Button.ToolTip>
                     </Button>
 
-                    <ToggleButton Name="LeftToolPanelButton" Margin="13,0,0,0" BorderThickness="0" Width="30" Height="30" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="LeftToolPanelButton_Click">
+                    <ToggleButton Name="LeftToolPanelButton" Margin="13,0,0,0" BorderThickness="0" Width="30" Height="30" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" IsChecked="{Binding LeftToolPanelButtonIsChecked, Mode=TwoWay}" Click="LeftToolPanelButton_Click">
                         <ToggleButton.Content>
                             <Path Fill="#43474D" Width="30" Height="30">
                                 <Path.Data>
@@ -119,10 +119,10 @@
                     <cpdftools:CPDFScalingControl x:Name="CPDFSaclingControl"></cpdftools:CPDFScalingControl>
                 </StackPanel>
 
-                <ComboBox Name="ModeComboBox" SelectedIndex="2" Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
+                <ComboBox Name="ModeComboBox" Style="{StaticResource ComboBoxStyle1}" Width="120" Height="26" Grid.Column="1" HorizontalAlignment="Center" FontSize="14" Foreground="#001A4E" SelectionChanged="ComboBox_SelectionChanged">
                     <ComboBoxItem Tag="Viewer">Viewer</ComboBoxItem>
                     <ComboBoxItem Tag="Annotation">Annotation</ComboBoxItem>
-                    <ComboBoxItem IsSelected="True" Tag="Form">Form</ComboBoxItem>
+                    <ComboBoxItem Tag="Form">Form</ComboBoxItem>
                 </ComboBox>
 
                 <StackPanel Orientation="Horizontal" Grid.Column="2">
@@ -144,7 +144,7 @@
                         </Button.ToolTip>
                     </Button>
 
-                    <ToggleButton  x:Name="RightPanelButton" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="RightPanelButton_Click">
+                    <ToggleButton  x:Name="RightPanelButton" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="RightPanelButton_Click" IsChecked="{Binding RightToolPanelButtonIsChecked, Mode=TwoWay}">
                         <ToggleButton.Content>
                             <Path Fill="#43474D" Width="30" Height="30">
                                 <Path.Data>
@@ -157,7 +157,7 @@
                         </ToggleButton.ToolTip>
                     </ToggleButton>
 
-                    <ToggleButton Name="ViewSettingBtn" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}" Background="Transparent" Click="ViewSettingBtn_Click">
+                    <ToggleButton Name="ViewSettingBtn" BorderThickness="0" Width="40" Height="40" Style="{StaticResource ToggleButtonStyle}"  Background="Transparent" IsChecked="{Binding ViewSettingBtnIsChecked, Mode=TwoWay}" Click="ViewSettingBtn_Click">
                         <ToggleButton.Content>
                             <Path Stroke="#43474D" VerticalAlignment="Center" StrokeThickness="2">
                                 <Path.Data>
@@ -204,7 +204,9 @@
                     <ColumnDefinition Width="*"></ColumnDefinition>
                     <ColumnDefinition Width="auto"></ColumnDefinition>
                 </Grid.ColumnDefinitions>
-
+                <Grid>
+                    
+                </Grid>
                 <GridSplitter  Name="Splitter" Grid.Column="1" Width="15" ResizeBehavior="PreviousAndNext" Visibility="Collapsed">
                     <GridSplitter.Template>
                         <ControlTemplate TargetType="{x:Type GridSplitter}">
@@ -234,13 +236,12 @@
                         </Grid.ColumnDefinitions>
                         <Border x:Name="PDFGrid" Background="#CECECE"></Border>
                     </Grid>
-
                 </Grid>
             </Grid>
         </Grid>
+        
         <Border Name="PopupBorder" Background="#A0000000" Visibility="Collapsed">
             <Grid>
-
                 <Grid Name="FileInfoUI"  Width="422" Height="680" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White" Visibility="Collapsed">
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="*"></ColumnDefinition>

+ 121 - 60
Demo/Examples/PDFViewer_new/MainPage.xaml.cs

@@ -26,16 +26,19 @@ namespace PDFViewer_new
 {
     public partial class MainPage : UserControl, INotifyPropertyChanged
     {
+        private string currentMode = "Viewer";
         private PDFViewControl pdfViewer;
         private PDFViewControl passwordViewer;
         private AnnotationControl annotationControl = new AnnotationControl();
         private FormControl formControl = new FormControl();
         private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl();
+        private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
+
+        private PanelState panelState = PanelState.GetInstance();
 
         private bool _canSave = false;
         public bool CanSave
         {
-
             get => _canSave;
             set
             {
@@ -43,13 +46,50 @@ namespace PDFViewer_new
                 OnPropertyChanged();
             }
         }
+
+        public bool LeftToolPanelButtonIsChecked
+        {
+            get => panelState.IsLeftPanelExpand;
+            set
+            {
+                panelState.IsLeftPanelExpand = value;
+                OnPropertyChanged();
+            }
+        }
+
+        public bool RightToolPanelButtonIsChecked
+        {
+            get
+            {
+                return (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel);
+            }
+            set
+            {
+                panelState.RightPanel = (value) ? PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
+                OnPropertyChanged();
+            }
+        }
+
+        public bool ViewSettingBtnIsChecked
+        {
+            get
+            {
+                return (panelState.RightPanel == PanelState.RightPanelState.ViewSettings);
+            }
+            set
+            {
+                panelState.RightPanel = (value) ? PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
+                OnPropertyChanged();
+            }
+        }
+
         public MainPage()
         {
             InitializeComponent();
+            this.DataContext = this;
         }
 
-                #region Load document
-
+        #region Load document
         private void LoadDefaultDocument()
         {
             string defaultFilePath = "PDF32000_2008.pdf";
@@ -62,7 +102,7 @@ namespace PDFViewer_new
         {
             pdfViewer.PDFView.Load();
             pdfViewer.PDFView.SetShowLink(true);
-            
+
             pdfViewer.PDFView.InfoChanged -= PdfViewer_InfoChanged;
             pdfViewer.PDFView.InfoChanged += PdfViewer_InfoChanged;
 
@@ -81,7 +121,16 @@ namespace PDFViewer_new
             botaBarControl.InitWithPDFViewer(pdfViewer.PDFView);
             botaBarControl.SelectBotaTool(BOTATools.Thumbnail);
             botaBarControl.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
+            displaySettingsControl.InitWithPDFViewer(pdfViewer.PDFView);
             LoadCustomControl();
+            panelState.PropertyChanged -= PanelState_PropertyChanged;
+            panelState.PropertyChanged += PanelState_PropertyChanged;
+            ModeComboBox.SelectedIndex = 2;
+        }
+
+        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+
         }
 
         private void PdfFormControlRefreshAnnotList(object sender, EventArgs e)
@@ -91,11 +140,11 @@ namespace PDFViewer_new
 
         private void FormControlOnCanSaveChanged(object sender, bool e)
         {
-           this.CanSave = e;
+            this.CanSave = e;
         }
 
         #endregion
-        
+
         #region Password
 
         private void PasswordUI_Confirmed(object sender, string e)
@@ -132,30 +181,29 @@ namespace PDFViewer_new
         }
 
         #endregion
-        
+
         #region Load Unload custom control
         private void LoadCustomControl()
         {
-            formControl.PdfViewControl = pdfViewer;
-            formControl.InitWithPDFViewer(pdfViewer.PDFView);
+            formControl.PdfViewControl = pdfViewer; 
             InitialPDFViewControl(formControl.PdfViewControl);
             formControl.OnCanSaveChanged -= FormControlOnCanSaveChanged;
             formControl.OnCanSaveChanged += FormControlOnCanSaveChanged;
             formControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
             formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
-            formControl.SetBOTAContainer(botaBarControl);
             formControl.InitialPDFViewControl(formControl.PdfViewControl);
-            
+
             annotationControl.PdfViewControl = pdfViewer;
+            //annotationControl.SetBOTAContainer(botaBarControl);
         }
-        
+
         private void MainWindow_Loaded(object sender, RoutedEventArgs e)
         {
             pdfViewer = new PDFViewControl();
             LoadDefaultDocument();
         }
         #endregion
-        
+
         #region Annotation
 
         public void InitialPDFViewControl(PDFViewControl newPDFViewer)
@@ -163,29 +211,29 @@ namespace PDFViewer_new
             formControl.ClearAllToolState();
             formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
         }
-          
+
         #endregion
-        
+
         #region Event handle
 
         private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
-        { 
+        {
             if (e.Key == "Zoom")
             {
                 CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
             }
         }
-        
-        
-        
+
+
+
         #endregion
-        
+
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
             pdfViewer.PDFView.UndoManager.CanSave = false;
         }
-        
+
         private void OpenFile()
         {
             string filePath = CommonHelper.GetFilePathOrEmpty();
@@ -230,23 +278,29 @@ namespace PDFViewer_new
 
         private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
         {
-            ToggleButton expandBtn = sender as ToggleButton;
-            if (expandBtn != null)
-            {
-                bool isExpand = expandBtn.IsChecked == true;
-                formControl.ExpandLeftPanel(isExpand);
-            }
+            panelState.IsLeftPanelExpand = (sender as ToggleButton).IsChecked == true;
         }
 
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
+
+            if (currentMode == "Annotation")
+            {
+                annotationControl.UnloadEvent();
+                annotationControl.ClearViewerControl();
+            }
+            else if (currentMode == "Form")
+            {
+                formControl.UnloadEvent();
+                annotationControl.ClearViewerControl();
+            }
+
             if ((string)item.Content == "Viewer")
             {
                 formControl.ClearAllToolState();
                 formControl.SetToolBarContainerVisibility(Visibility.Collapsed);
                 formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
-                //formControl.FromPropertyControl.AnnotationCancel();
                 RightPanelButton.IsChecked = false;
                 if (formControl.PdfViewControl != null && formControl.PdfViewControl.PDFView != null)
                 {
@@ -258,9 +312,9 @@ namespace PDFViewer_new
                 annotationControl.SetToolBarContainerVisibility(Visibility.Visible);
                 if (annotationControl.PdfViewControl != null && annotationControl.PdfViewControl.PDFView != null)
                 {
-                    formControl.UnloadEvent();
-                    formControl.ClearViewerControl();
                     PDFGrid.Child = annotationControl;
+                    formControl.ClearViewerControl(); 
+
                     annotationControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
                     annotationControl.PdfViewControl = pdfViewer;
                     annotationControl.InitWithPDFViewer(pdfViewer.PDFView);
@@ -269,8 +323,9 @@ namespace PDFViewer_new
                     annotationControl.OnCanSaveChanged += FormControlOnCanSaveChanged;
                     annotationControl.OnAnnotEditHandler -= PdfFormControlRefreshAnnotList;
                     annotationControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
-                    annotationControl.SetBOTAContainer(botaBarControl);
                     annotationControl.InitialPDFViewControl(annotationControl.PdfViewControl);
+                    annotationControl.SetBOTAContainer(botaBarControl);
+                    annotationControl.SetDisplaySettingsControl(displaySettingsControl);
                 }
             }
             else if ((string)item.Content == "Form")
@@ -278,8 +333,6 @@ namespace PDFViewer_new
                 formControl.SetToolBarContainerVisibility(Visibility.Visible);
                 if (formControl.PdfViewControl != null && formControl.PdfViewControl.PDFView != null)
                 {
-                    annotationControl.UnloadEvent();
-                    annotationControl.ClearViewerControl();
                     PDFGrid.Child = formControl;
                     formControl.PdfViewControl.PDFView.SetMouseMode(MouseModes.FormEditTool);
                     formControl.PdfViewControl = pdfViewer;
@@ -291,8 +344,10 @@ namespace PDFViewer_new
                     formControl.OnAnnotEditHandler += PdfFormControlRefreshAnnotList;
                     formControl.SetBOTAContainer(botaBarControl);
                     formControl.InitialPDFViewControl(formControl.PdfViewControl);
+                    formControl.SetDisplaySettingsControl(displaySettingsControl);
                 }
             }
+            currentMode = (string)item.Content;
         }
 
         private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
@@ -305,7 +360,10 @@ namespace PDFViewer_new
 
         private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
         {
-            ShowViewSettings();
+            //ShowViewSettings();
+            panelState.RightPanel =
+               ((sender as ToggleButton).IsChecked == true) ?
+               PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
         }
 
         private void ShowViewSettings()
@@ -316,7 +374,7 @@ namespace PDFViewer_new
                 {
                     CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
                     displayPanel.InitWithPDFViewer(formControl.PdfViewControl.PDFView);
-                    formControl.SetViewSettings(Visibility.Visible, displayPanel); 
+                    formControl.SetViewSettings(Visibility.Visible, displayPanel);
                     if ((bool)RightPanelButton.IsChecked)
                     {
                         RightPanelButton.IsChecked = false;
@@ -324,13 +382,16 @@ namespace PDFViewer_new
                 }
                 else
                 {
-                    formControl.SetViewSettings(Visibility.Collapsed); 
+                    formControl.SetViewSettings(Visibility.Collapsed);
                 }
             }
         }
+
         private void RightPanelButton_Click(object sender, RoutedEventArgs e)
         {
-            ControlRightPanel();
+            panelState.RightPanel =
+                ((sender as ToggleButton).IsChecked == true) ?
+                PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
         }
 
         private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
@@ -338,28 +399,28 @@ namespace PDFViewer_new
             formControl.ExpandLeftPanel(true);
             botaBarControl.SelectBotaTool(BOTATools.Search);
         }
-        
-        private void ControlRightPanel()
-        { 
-            if (RightPanelButton != null)
-            {
-                if (RightPanelButton.IsChecked == true)
-                {
-                    if (formControl.FromPropertyControl != null)
-                    {
-                        formControl.ExpandRightPropertyPanel(formControl.FromPropertyControl, Visibility.Visible);
-                        if ((bool)ViewSettingBtn.IsChecked)
-                        {
-                            ViewSettingBtn.IsChecked = false;
-                        }
-                    }
-                }
-                else
-                {
-                    formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
-                }
-            }
-        }
+
+        //private void ControlRightPanel()
+        //{
+        //    if (RightPanelButton != null)
+        //    {
+        //        if (RightPanelButton.IsChecked == true)
+        //        {
+        //            if (formControl.FromPropertyControl != null)
+        //            {
+        //                formControl.ExpandRightPropertyPanel(formControl.FromPropertyControl, Visibility.Visible);
+        //                if ((bool)ViewSettingBtn.IsChecked)
+        //                {
+        //                    ViewSettingBtn.IsChecked = false;
+        //                }
+        //            }
+        //        }
+        //        else
+        //        {
+        //            formControl.ExpandRightPropertyPanel(null, Visibility.Collapsed);
+        //        }
+        //    }
+        //}
 
         #region Save file
         /// <summary>
@@ -423,10 +484,10 @@ namespace PDFViewer_new
         }
 
         public event PropertyChangedEventHandler PropertyChanged;
-        
         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
     }
+
 }