فهرست منبع

其他-调整底部工具栏加载方式

ZhouJieSheng 2 سال پیش
والد
کامیت
92b55bdbda

+ 1 - 0
PDF Office/App.xaml.cs

@@ -107,6 +107,7 @@ namespace PDF_Office
             containerRegistry.RegisterForNavigation<BOTAContent>();
             containerRegistry.RegisterForNavigation<PropertyPanelContent>();
             containerRegistry.RegisterForNavigation<PageEditContent>();
+            containerRegistry.RegisterForNavigation<BottomToolContent>();
             containerRegistry.RegisterForNavigation<ToolsBarContent>();
             containerRegistry.RegisterForNavigation<AnnotToolContent>();
             containerRegistry.RegisterForNavigation<BookmarkContent>();

+ 11 - 0
PDF Office/Model/RegionNames.cs

@@ -83,6 +83,17 @@ namespace PDF_Office.Model
             }
         }
 
+        /// <summary>
+        /// 底部工具栏对应的Content RegionName
+        /// </summary>
+        public static string BottomToolRegionName
+        {
+            get
+            {
+                return GetRegionName("BottomToolRegionName");
+            }
+        }
+
         /// <summary>
         /// 获取MainWindowsViewModel RegionNames字典里的RegionName,
         /// 如果字典里没有键值就新建一个GUID,并插入到

+ 35 - 22
PDF Office/ViewModels/BottomToolContentViewModel.cs

@@ -18,7 +18,7 @@ using PDF_Office.Model;
 
 namespace PDF_Office.ViewModels
 {
-    public class BottomToolContentViewModel : BindableBase
+    public class BottomToolContentViewModel : BindableBase, INavigationAware
     {
 
         public DelegateCommand Load { get; set; }
@@ -155,6 +155,8 @@ namespace PDF_Office.ViewModels
 
         public CPDFViewer PDFViewer { get; set; }
 
+        private ViewContentViewModel viewContentViewModel { get; set; }
+
 
         private IRegionManager region;
 
@@ -165,8 +167,6 @@ namespace PDF_Office.ViewModels
             region = regionManager;
             dialogs = dialogService;
 
-            Load = new DelegateCommand(LoadControl);
-
             PrePageCommand = new DelegateCommand(GoPrePage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
             NextPageCommand = new DelegateCommand(GoNextPage, CanNextPageExcute).ObservesProperty(() => CurrentPage);
             FirstPageCommand = new DelegateCommand(GoFirstPage, CanPrePageExcute).ObservesProperty(() => CurrentPage);
@@ -401,25 +401,6 @@ namespace PDF_Office.ViewModels
             return false;
         }
 
-
-        private void LoadControl()
-        {
-            if (App.mainWindowViewModel.CurrentPDFViewer != null)
-            {
-                PDFViewer = App.mainWindowViewModel.CurrentPDFViewer;
-                if (PDFViewer != null)
-                {
-                    //获取页面设置等信息
-                    PageCount = PDFViewer.Document.PageCount;
-                    GetModeView(PDFViewer.ModeView);
-                    CurrentPage = PDFViewer.CurrentIndex+1;
-                    CurrentZoom = PDFViewer.ZoomFactor*100;
-                    PDFViewer.InfoChanged += PDFViewer_InfoChanged;
-                }
-
-            }
-        }
-
         private void PDFViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
         {
             if (e.Key == "PageNum")
@@ -516,5 +497,37 @@ namespace PDF_Office.ViewModels
             }
         }
 
+        #region Navigation
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            var viewContentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
+            if (viewContentViewModel != null)
+            {
+                this.viewContentViewModel = viewContentViewModel;
+            }
+
+            var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
+            if(pdfview!=null)
+            {
+                //获取页面设置等信息
+                PDFViewer = pdfview;
+                PageCount = PDFViewer.Document.PageCount;
+                GetModeView(PDFViewer.ModeView);
+                CurrentPage = PDFViewer.CurrentIndex + 1;
+                CurrentZoom = PDFViewer.ZoomFactor * 100;
+                PDFViewer.InfoChanged += PDFViewer_InfoChanged;
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+
+        }
+        #endregion
     }
 }

+ 7 - 1
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -44,6 +44,11 @@ namespace PDF_Office.ViewModels
 
         public string ToolsBarContentRegionName { get; set; }
 
+        /// <summary>
+        /// 底部工具栏 RegionName
+        /// </summary>
+        public string BottomToolRegionName { get; set; }
+
         /// <summary>
         /// 是否处于页面编辑模式,用于执行undo redo 的具体操作
         /// </summary>
@@ -256,6 +261,7 @@ namespace PDF_Office.ViewModels
             ViwerRegionName = RegionNames.ViwerRegionName;
             BOTARegionName = RegionNames.BOTARegionName;
             PropertyRegionName = RegionNames.PropertyRegionName;
+            BottomToolRegionName = RegionNames.BottomToolRegionName;
 
             //未显示时无法注册上Region名称
             ToolContentVisible = Visibility.Visible;
@@ -445,7 +451,7 @@ namespace PDF_Office.ViewModels
                 parameters.Add(ParameterNames.PDFViewer, PDFViewer);
                 parameters.Add(ParameterNames.ViewContentViewModel, this);
                 region.RequestNavigate(BOTARegionName, "BOTAContent",parameters);
-
+                region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
 
                 //TODO 根据上一次关闭记录的菜单,选中TabItem
                 EnterSelectedBar("TabItemAnnotation");

+ 0 - 5
PDF Office/Views/BottomToolContent.xaml

@@ -51,11 +51,6 @@
             </Setter>
         </Style>
     </UserControl.Resources>
-    <i:Interaction.Triggers>
-        <i:EventTrigger EventName="Loaded">
-            <prism:InvokeCommandAction Command="{Binding Load}" />
-        </i:EventTrigger>
-    </i:Interaction.Triggers>
     <Grid Height="32">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="*" />

+ 1 - 1
PDF Office/Views/ViewContent.xaml

@@ -205,7 +205,7 @@
 
         </Grid>
 
-        <local:BottomToolContent Grid.Row="3" />
+        <ContentControl Grid.Row="3" prism:RegionManager.RegionName="{Binding BottomToolRegionName}" />
 
         <!--  用于显示页面编辑、水印、背景、标记密文等功能的区域  -->
         <ContentControl