Переглянути джерело

bota-补充Bota部分逻辑

ZhouJieSheng 2 роки тому
батько
коміт
d32a516dd6

+ 77 - 3
PDF Office/ViewModels/BOTA/BOTAContentViewModel.cs

@@ -5,19 +5,84 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Model;
+using Prism.Commands;
+using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels.BOTA
 {
     public class BOTAContentViewModel:BindableBase, INavigationAware
     {
 
-        public BOTAContentViewModel()
+        private CPDFViewer pdfViewer { get; set; }
+
+        private IRegionManager regions { get; set; }
+
+        private ViewContentViewModel viewContentViewModel { get; set; }
+
+        private Dictionary<string, string> viewNameByTabItem { get; set; }
+
+        private string botaContentRegionName;
+
+        public string BOTAContentRegionNmae
         {
+            get { return botaContentRegionName; }
+            set
+            {
+                SetProperty(ref botaContentRegionName, value);
+            }
+        }
 
+        public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
+
+        public BOTAContentViewModel(IRegionManager regionManager)
+        {
+            regions = regionManager;
+            
+            BOTAContentRegionNmae = Guid.NewGuid().ToString();
+
+            InitDictionartViewNameByTabItem();
         }
 
-        #region Navigate
 
+        private void TabControlSelectionChangedEvent(object e)
+        {
+            var args = e as SelectionChangedEventArgs;
+            if (args != null)
+            {
+                EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
+            }
+        }
+
+        /// <summary>
+        /// 初始化名称-视图字典
+        /// </summary>
+        private void InitDictionartViewNameByTabItem()
+        {
+            viewNameByTabItem = new Dictionary<string, string>();
+            //绑定tabitem名字和对应的View控件名称
+            viewNameByTabItem.Add("TabItemThumbnail","");
+            viewNameByTabItem.Add("TabItemOutLine", "");
+            viewNameByTabItem.Add("TabItemBookMark", "");
+            viewNameByTabItem.Add("TabItemAnnotation", "");
+            viewNameByTabItem.Add("TabItemSearch", "");
+            viewNameByTabItem.Add("TabItemForm", "");
+            viewNameByTabItem.Add("TabItemSign", "");
+        }
+
+        /// <summary>
+        /// 导航至目标TabItem
+        /// </summary>
+        /// <param name="currentBar"></param>
+        private void EnterSelectedBar(string currentBar)
+        {
+            NavigationParameters param = new NavigationParameters();
+            param.Add(ParameterNames.PDFViewer, pdfViewer);
+            regions.RequestNavigate(BOTAContentRegionNmae, viewNameByTabItem[currentBar], param);
+        }
+
+        #region Navigate
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -30,7 +95,16 @@ namespace PDF_Office.ViewModels.BOTA
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
-            
+            var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
+            if (contentViewModel != null)
+            {
+                viewContentViewModel = contentViewModel;
+            }
+            var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
+            if (pdfview != null)
+            {
+                pdfViewer = pdfview;
+            }
         }
         #endregion
     }

+ 4 - 6
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -245,8 +245,6 @@ namespace PDF_Office.ViewModels
             dictionary.Add("TabItemFill", "");
         }
 
-
-
         private void UndoManager_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
         {
             if (e.PropertyName == "CanSave")
@@ -263,9 +261,6 @@ namespace PDF_Office.ViewModels
             }
         }
 
-
-
-
         /// <summary>
         /// 选项卡切换事件
         /// </summary>
@@ -397,7 +392,10 @@ namespace PDF_Office.ViewModels
             //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成,加载BOTA区域
             System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
             {
-                region.RequestNavigate(BOTARegionName, "BOTAContent");
+                NavigationParameters parameters = new NavigationParameters();
+                parameters.Add(ParameterNames.PDFViewer, PDFViewer);
+                parameters.Add(ParameterNames.ViewContentViewModel, this);
+                region.RequestNavigate(BOTARegionName, "BOTAContent",parameters);
             }
             ));
         }

+ 14 - 1
PDF Office/Views/BOTA/BOTAContent.xaml

@@ -2,11 +2,14 @@
     x:Class="PDF_Office.Views.BOTA.BOTAContent"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:bota="clr-namespace:PDF_Office.ViewModels.BOTA"
     xmlns:convert="clr-namespace:PDF_Office.DataConvert"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
     xmlns:local="clr-namespace:PDF_Office.Views.BOTA"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
+    d:DataContext="{d:DesignInstance Type=bota:BOTAContentViewModel}"
     d:DesignHeight="450"
     d:DesignWidth="800"
     prism:ViewModelLocator.AutoWireViewModel="True"
@@ -67,8 +70,12 @@
             Background="Transparent"
             Style="{StaticResource TabControlWithUnderLineStyle}"
             TabStripPlacement="Left">
+
             <!--  建立一个空的标头占位  -->
-            <TabItem Height="0" BorderThickness="0" />
+            <TabItem
+                Height="0"
+                Margin="0"
+                BorderThickness="0" />
             <TabItem
                 Name="TabItemThumbnail"
                 Width="48"
@@ -111,6 +118,12 @@
                 Height="48"
                 Header="签名"
                 Visibility="{Binding ElementName=MenuSign, Path=IsChecked, Converter={StaticResource BoolToVisibleConvert}, Mode=TwoWay}" />
+            <i:Interaction.Triggers>
+                <i:EventTrigger EventName="SelectionChanged">
+                    <i:InvokeCommandAction Command="{Binding TabControlSelectionChangedCommand}" PassEventArgsToCommand="True" />
+                </i:EventTrigger>
+            </i:Interaction.Triggers>
         </TabControl>
+        <ContentControl Grid.Column="1" prism:RegionManager.RegionName="{Binding BOTAContentRegionName}" />
     </Grid>
 </UserControl>