Prechádzať zdrojové kódy

其他-补充部分文件

ZhouJieSheng 2 rokov pred
rodič
commit
ffa5958997

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

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
 using System.Windows;
 using ComPDFKit.NativeMethod;
 using ComPDFKit_Conversion.Converter;
+using PDF_Office.ViewModels;
 using PDF_Office.Views;
 using PDF_Office.Views.HomePanel;
 using Prism.DryIoc;
@@ -20,6 +21,9 @@ namespace PDF_Office
     /// </summary>
     public partial class App : PrismApplication
     {
+        public static MainWindowViewModel mainWindowViewModel;
+
+        public static List<string> OpenedFileList = new List<string>();
 
         public App()
         {
@@ -45,11 +49,13 @@ namespace PDF_Office
             return Container.Resolve<MainWindow>();
         }
 
+
         protected override void RegisterTypes(IContainerRegistry containerRegistry)
         {
             //单例
             containerRegistry.RegisterForNavigation<HomeContent>();
             containerRegistry.RegisterForNavigation<ViewContent>();
+            containerRegistry.RegisterForNavigation<MainContent>();
             containerRegistry.RegisterForNavigation<HomeCloudContent>("Cloud");
             containerRegistry.RegisterForNavigation<HomeToolsContent>("Tools");
             containerRegistry.RegisterForNavigation<HomeGuidContent>("Guid");
@@ -111,5 +117,11 @@ namespace PDF_Office
             catch (Exception ex) { }
             return result;
         }
+
+        protected override void OnExit(ExitEventArgs e)
+        {
+            Environment.Exit(1);
+            base.OnExit(e);
+        }
     }
 }

+ 16 - 0
PDF Office/CustomControl/RegionNames.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.CustomControl
+{
+    public static class RegionNames
+    {
+        /// <summary>
+        /// 最外层的Region名称
+        /// </summary>
+        public static string MainRegion = "MainRegion";
+    }
+}

+ 41 - 0
PDF Office/CustomControl/TabItemEx.cs

@@ -0,0 +1,41 @@
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PDF_Office.CustomControl
+{
+    public class TabItemEx : BindableBase
+    {
+        private string fileName;
+
+        public string FileName
+        {
+            get { return fileName; }
+            set { SetProperty(ref fileName, value); }
+        }
+
+        private string contentName;
+
+        public string ContentName
+        {
+            get { return contentName; }
+            set { SetProperty(ref contentName, value); }
+        }
+
+        private bool isSelected;
+
+        public bool IsSelected
+        {
+            get { return isSelected; }
+            set { SetProperty(ref isSelected, value); }
+        }
+
+    }
+}

+ 21 - 1
PDF Office/PDF Office.csproj

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="packages\Xamarin.Forms.5.0.0.2012\build\Xamarin.Forms.props" Condition="Exists('packages\Xamarin.Forms.5.0.0.2012\build\Xamarin.Forms.props')" />
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -14,6 +15,8 @@
     <WarningLevel>4</WarningLevel>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
     <Deterministic>true</Deterministic>
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -99,10 +102,13 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="CustomControl\RegionNames.cs" />
+    <Compile Include="CustomControl\TabItemEx.cs" />
     <Compile Include="EventAggregators\OpenFileEvent.cs" />
     <Compile Include="ViewModels\HomePanel\HomeCloudContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeGuidContentViewModel.cs" />
     <Compile Include="ViewModels\HomePanel\HomeToolsContentViewModel.cs" />
+    <Compile Include="ViewModels\MainContentViewModel.cs" />
     <Compile Include="Views\HomePanel\HomeCloudContent.xaml.cs">
       <DependentUpon>HomeCloudContent.xaml</DependentUpon>
     </Compile>
@@ -112,6 +118,9 @@
     <Compile Include="Views\HomePanel\HomeToolsContent.xaml.cs">
       <DependentUpon>HomeToolsContent.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\MainContent.xaml.cs">
+      <DependentUpon>MainContent.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Views\ViewContent.xaml.cs">
       <DependentUpon>ViewContent.xaml</DependentUpon>
     </Compile>
@@ -131,6 +140,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Views\MainContent.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Views\MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -183,9 +196,11 @@
   </ItemGroup>
   <ItemGroup>
     <Folder Include="DataConvert\" />
-    <Folder Include="Helper\" />
     <Folder Include="Model\" />
     <Folder Include="Resources\" />
+    <Folder Include="Tools\" />
+    <Folder Include="ViewModels\BOTA\" />
+    <Folder Include="Views\BOTA\" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="ComOCRKit.Desk.dll">
@@ -271,4 +286,9 @@
     </Content>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
+    </PropertyGroup>
+  </Target>
 </Project>

+ 77 - 6
PDF Office/ViewModels/HomeContentViewModel.cs

@@ -1,4 +1,5 @@
-using PDF_Office.EventAggregators;
+using Microsoft.Win32;
+using PDF_Office.EventAggregators;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
@@ -11,8 +12,24 @@ using System.Threading.Tasks;
 
 namespace PDF_Office.ViewModels
 {
-    public class HomeContentViewModel:BindableBase
+    public class HomeContentViewModel : BindableBase, INavigationAware
     {
+        private string fileName = "Home";
+        public string FileName
+        {
+            get { return fileName; }
+            set { SetProperty(ref fileName, value); }
+        }
+
+        private string regionName;
+
+        public string RegionName
+        {
+            get { return regionName; }
+            set { SetProperty(ref regionName, value); }
+        }
+
+        private MainContentViewModel mainContentViewModel;
 
         public DelegateCommand OpenFileCommand { get; set; }
 
@@ -26,6 +43,8 @@ namespace PDF_Office.ViewModels
         {
             toolregion = regionManager;
             eventer = eventAggregator;
+
+            RegionName = Guid.NewGuid().ToString();
             OpenFileCommand = new DelegateCommand(OpenFile);
             ShowToolCommand = new DelegateCommand<string>(ShowToolContent);
         }
@@ -36,20 +55,72 @@ namespace PDF_Office.ViewModels
         /// <param name="view"></param>
         public void ShowToolContent(string view)
         {
-            this.toolregion.Regions["ToolContent"].RequestNavigate(view);
+            toolregion.RequestNavigate(RegionName, view);
         }
-        
+
         /// <summary>
         /// 打开文件
         /// </summary>
         public void OpenFile()
         {
-            eventer.GetEvent<OpenFileEvent>().Publish();
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
+            openFileDialog.Multiselect = true;
+            if ((bool)openFileDialog.ShowDialog())
+            {
+
+                if (openFileDialog.FileNames.Count() == 1)
+                {
+                    if (App.OpenedFileList.Contains(openFileDialog.FileName))
+                    {
+                        App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
+                    }
+                    else
+                    {
+                        mainContentViewModel.OpenFile(openFileDialog.FileName);
+                    }
+                }
+                else
+                {
+                    var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
+                    if (fileList.Count <= 0)
+                        return;
+                    mainContentViewModel.OpenFile(fileList[0]);
+                    for (int i = 1; i < fileList.Count(); i++)
+                    {
+                        if (!App.OpenedFileList.Contains(fileList[i]))
+                        {
+                            App.mainWindowViewModel.AddTabItem(fileList[i]);
+                        }
+                    }
+
+                }
+            }
         }
 
         public void CreatBlankPDF()
         {
-               
+
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            var mainVM = navigationContext.Parameters["MainViewModel"] as MainContentViewModel;
+            if (mainVM != null)
+            {
+                mainContentViewModel = mainVM;
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+
         }
     }
 }

+ 150 - 0
PDF Office/ViewModels/MainContentViewModel.cs

@@ -0,0 +1,150 @@
+using Microsoft.Win32;
+using PDF_Office.EventAggregators;
+using PDF_Office.Views;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Ioc;
+using Prism.Mvvm;
+using Prism.Regions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PDF_Office.ViewModels
+{
+    public enum LoadType
+    {
+        /// <summary>
+        /// 打开文档
+        /// </summary>
+        Open,
+        /// <summary>
+        /// 创建文档
+        /// </summary>
+        Create
+    }
+    public class MainContentViewModel : BindableBase, INavigationAware
+    {
+        private string fileName = "Home";
+
+        public string FileName
+        {
+            get { return fileName; }
+            set { SetProperty(ref fileName, value); }
+        }
+
+        private string filePath;
+
+        public string FilePath
+        {
+            get { return filePath; }
+            set
+            {
+                SetProperty(ref filePath, value);
+                if (!string.IsNullOrEmpty(filePath))
+                {
+                    FileName = System.IO.Path.GetFileName(filePath);
+                }
+
+            }
+        }
+
+        private Visibility fileChanged;
+
+        public Visibility FileChanged
+        {
+            get { return fileChanged; }
+            set { SetProperty(ref fileChanged, value); }
+        }
+
+
+        public DelegateCommand<object> CloseTab { get; set; }
+
+
+        private string regionName;
+
+        public string RegionName
+        {
+            get { return regionName; }
+            set { SetProperty(ref regionName, value); }
+        }
+
+        public IRegionManager toolregion;
+
+        public IEventAggregator eventer;
+
+        public IContainerProvider container;
+
+        public MainContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IContainerProvider containerProvider)
+        {
+            toolregion = regionManager;
+            eventer = eventAggregator;
+            container = containerProvider;
+
+            CloseTab = new DelegateCommand<object>(CloseTabItem);
+
+            RegionName = Guid.NewGuid().ToString();
+
+            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+            {
+                NavigationParameters parameters = new NavigationParameters
+                {
+                    {
+                        "MainViewModel", this
+                    }
+                };
+                toolregion.RequestNavigate(RegionName, "HomeContent", parameters);
+            }));
+        }
+
+
+        private void CloseTabItem(object item)
+        {
+            App.mainWindowViewModel?.CloseTabItem(item);
+            App.OpenedFileList.Remove(FilePath);
+        }
+
+
+        public void OpenFile(string filePath)
+        {
+            FilePath = filePath;
+            NavigationParameters parameters = new NavigationParameters { { "MainViewModel", this } };
+            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+            {
+                toolregion.RequestNavigate(RegionName, "ViewContent", parameters);
+            }));
+     
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            if (navigationContext.Parameters.Count <= 0)
+                return;
+            var filepath = navigationContext.Parameters["filePath"];
+            if(filepath!=null)
+            {
+                OpenFile(filepath.ToString());
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            if (navigationContext.Parameters.Count <= 0)
+                return true;
+            var isAddTab = navigationContext.Parameters["AddTab"];
+            if (isAddTab!=null&&(bool)isAddTab)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+
+        }
+    }
+}

+ 74 - 11
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -1,4 +1,6 @@
-using PDF_Office.EventAggregators;
+using Microsoft.Win32;
+using PDF_Office.CustomControl;
+using PDF_Office.EventAggregators;
 using PDF_Office.Views;
 using Prism.Commands;
 using Prism.Events;
@@ -6,37 +8,98 @@ using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Controls;
 
 namespace PDF_Office.ViewModels
 {
-    public class MainWindowViewModel:BindableBase
+    public class MainWindowViewModel : BindableBase
     {
-        private string _title = "PDF Office";
-        public string Title
+        /// <summary>
+        /// 当前选中项
+        /// </summary>
+        //public MainContent SelectedItem { get; set; }
+
+        private MainContent selectedItem;
+
+        public MainContent SelectedItem
         {
-            get { return _title; }
-            set { SetProperty(ref _title, value); }
+            get { return selectedItem; }
+            set { SetProperty(ref selectedItem, value); }
         }
 
+
+        public DelegateCommand AddTab { get; set; }
+
+
         public IRegionManager region;
 
         public IEventAggregator eventer;
 
         public MainWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
         {
+            App.mainWindowViewModel = this;
             region = regionManager;
             eventer = eventAggregator;
-            //region.RequestNavigate("ViwerRegion", "HomeContent");
-            eventer.GetEvent<OpenFileEvent>().Subscribe(OpenFile);
-            region.RegisterViewWithRegion("ViwerRegion",typeof(HomeContent));
+
+            AddTab = new DelegateCommand(AddTabItem);
+
+            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { region.RequestNavigate(RegionNames.MainRegion, "MainContent"); }));
+            
+        }
+
+        public MainWindowViewModel()
+        {
+
         }
 
-        public void OpenFile()
+        /// <summary>
+        /// 单击+号时添加页签
+        /// </summary>
+        private void AddTabItem()
         {
-            region.RequestNavigate("ViwerRegion", "ViewContent");
+            NavigationParameters parameters = new NavigationParameters
+            {
+                { "AddTab",true}
+            };
+            region.RequestNavigate(RegionNames.MainRegion, "MainContent", parameters);
+        }
+
+        /// <summary>
+        /// 选择多文档打开时
+        /// </summary>
+        /// <param name="filePath"></param>
+        public void AddTabItem(string filePath)
+        {
+            NavigationParameters parameters = new NavigationParameters
+            {
+                { "filePath", filePath },
+                { "AddTab",true}
+            };
+            region.RequestNavigate(RegionNames.MainRegion, "MainContent", parameters);
+        }
+
+        public void CloseTabItem(object item)
+        {
+            if (region.Regions[RegionNames.MainRegion].Views.Count() > 1)
+            {
+                region.Regions[RegionNames.MainRegion].Remove(item);
+            }
+            else
+            {
+                App.Current.MainWindow.Close();
+            }
+            return;
+        }
+
+        public void SelectItem(string filepath)
+        {
+            var item = region.Regions[RegionNames.MainRegion].Views.Where(t => ((t as MainContent).DataContext as MainContentViewModel).FilePath == filepath).FirstOrDefault() as MainContent;
+            SelectedItem = item;
+
         }
     }
 }

+ 91 - 11
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -8,42 +8,122 @@ using System.Text;
 using System.Threading.Tasks;
 using ComPDFKitViewer.PdfViewer;
 using Prism.Regions;
+using DryIoc;
 
 namespace PDF_Office.ViewModels
 {
 
-    public class ViewContentViewModel : BindableBase
+    public class ViewContentViewModel : BindableBase, INavigationAware
     {
         public DelegateCommand LoadFile { get; set; }
 
         private CPDFViewer PDFViewer { get; set; }
 
+        private MainContentViewModel mainViewModel { get; set; }
+
         public IRegionManager region;
 
+        public string ViwerRegionName { get; set; }
+
+        public string BOTARegionName { get; set; }
+
+        public string PropertyRegionName { get; set; }
+
+        private bool isOpenFile = false;
+
+        /// <summary>
+        /// 鼠标滚轮缩放的缩放值
+        /// </summary>
+        private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
+
         public ViewContentViewModel(IRegionManager regionManager)
         {
             LoadFile = new DelegateCommand(loadFile);
             region = regionManager;
-            //在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成
-            System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { loadFile(); }));
+
+            ViwerRegionName = Guid.NewGuid().ToString();
+            BOTARegionName = Guid.NewGuid().ToString();
+            PropertyRegionName = Guid.NewGuid().ToString();
+            ////在构造函数中使用Region需要借助Dispatcher 确保UI已经加载完成
+            //System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() => { loadFile(); }));
 
 
         }
 
+
         private void loadFile()
         {
-            OpenFileDialog openFileDialog = new OpenFileDialog();
-            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
-            if ((bool)openFileDialog.ShowDialog())
+            if (mainViewModel == null || string.IsNullOrEmpty(mainViewModel.FileName))
+            {
+                return;
+            }
+            string filepath = mainViewModel.FilePath;
+            PDFViewer = new CPDFViewer();
+            PDFViewer.MouseWheelZoomHandler += PdfViewer_MouseWheelZoomHandler;
+            PDFViewer.InitDocument(filepath);
+            PDFViewer.Load();
+            App.OpenedFileList.Add(filepath);
+            region.AddToRegion(ViwerRegionName, PDFViewer);
+        }
+
+        private void PdfViewer_MouseWheelZoomHandler(object sender, bool e)
+        {
+            double newZoom = CheckZoomLevel(PDFViewer.ZoomFactor + (e ? 0.01 : -0.01), e);
+            PDFViewer.Zoom(newZoom);
+        }
+
+        private double CheckZoomLevel(double zoom, bool IsGrowth)
+        {
+            double standardZoom = 100;
+            if (zoom <= 0.01)
             {
-                string file = openFileDialog.FileName;
-                var PDFViewer = new CPDFViewer();
-                PDFViewer.InitDocument(file);
-                PDFViewer.Load();
-                region.AddToRegion("PDFViewer", PDFViewer);
+                return 0.01;
             }
+            if (zoom >= 10)
+            {
+                return 10;
+            }
+
+            zoom *= 100;
+            for (int i = 0; i < zoomLevel.Length - 1; i++)
+            {
+                if (zoom > zoomLevel[i] && zoom <= zoomLevel[i + 1] && IsGrowth)
+                {
+                    standardZoom = zoomLevel[i + 1];
+                    break;
+                }
+                if (zoom >= zoomLevel[i] && zoom < zoomLevel[i + 1] && !IsGrowth)
+                {
+                    standardZoom = zoomLevel[i];
+                    break;
+                }
+            }
+            return standardZoom / 100;
+        }
+
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            if (isOpenFile)
+                return;
+
+            var mainVM = navigationContext.Parameters["MainViewModel"] as MainContentViewModel;
+            if(mainVM!=null)
+            {
+                mainViewModel = mainVM;
+            }
+            loadFile();
+            isOpenFile = true;
+        }
 
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
         }
 
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+            
+        }
     }
 }

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

@@ -54,6 +54,6 @@
                 Content="Cloud" />
         </StackPanel>
         <!--  右侧内容区域  -->
-        <ContentControl Grid.Column="1" prism:RegionManager.RegionName="ToolContent" />
+        <ContentControl Grid.Column="1" prism:RegionManager.RegionName="{Binding RegionName}" />
     </Grid>
 </UserControl>

+ 14 - 0
PDF Office/Views/MainContent.xaml

@@ -0,0 +1,14 @@
+<UserControl
+    x:Class="PDF_Office.Views.MainContent"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:PDF_Office.Views"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    xmlns:prism="http://prismlibrary.com/"
+    d:DesignHeight="450"
+    d:DesignWidth="800"
+    prism:ViewModelLocator.AutoWireViewModel="True"
+    mc:Ignorable="d">
+    <ContentControl prism:RegionManager.RegionName="{Binding RegionName}" />
+</UserControl>

+ 28 - 0
PDF Office/Views/MainContent.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PDF_Office.Views
+{
+    /// <summary>
+    /// MainContent.xaml 的交互逻辑
+    /// </summary>
+    public partial class MainContent : UserControl
+    {
+        public MainContent()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 21 - 13
PDF Office/Views/MainWindow.xaml

@@ -2,18 +2,20 @@
     x:Class="PDF_Office.Views.MainWindow"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:cus="clr-namespace:PDF_Office.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"
+    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
     xmlns:local="clr-namespace:PDF_Office"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
     xmlns:viewmodels="clr-namespace:PDF_Office.ViewModels"
-    Title="{Binding Title}"
     Width="1280"
     Height="800"
     MinWidth="1280"
     MinHeight="800"
     prism:ViewModelLocator.AutoWireViewModel="True"
+    Activated="Window_Activated"
     WindowStartupLocation="CenterScreen"
     mc:Ignorable="d">
     <WindowChrome.WindowChrome>
@@ -55,7 +57,7 @@
                                             MaxWidth="145"
                                             Margin="8,4,0,4"
                                             FontFamily="Segoe UI,Microsoft YaHei"
-                                            Text="{Binding FileName}"
+                                            Text="{Binding DataContext.FileName}"
                                             TextTrimming="WordEllipsis" />
                                         <Thumb
                                             x:Name="PART_Thumb"
@@ -64,7 +66,7 @@
                                             VerticalContentAlignment="Stretch"
                                             Background="Transparent"
                                             FontFamily="Segoe UI,Microsoft YaHei"
-                                            ToolTip="{Binding FileName}">
+                                            ToolTip="{Binding DataContext.FileName}">
                                             <Thumb.Template>
                                                 <ControlTemplate>
                                                     <Grid Background="Transparent" />
@@ -80,8 +82,17 @@
                                             VerticalAlignment="Top"
                                             IsHitTestVisible="False"
                                             Text="*"
-                                            Visibility="{Binding FileChanged}" />
-
+                                            Visibility="{Binding DataContext.FileChanged}" />
+                                        <Button
+                                            Grid.Column="2"
+                                            Width="16"
+                                            Height="16"
+                                            Margin="0,4,8,4"
+                                            Background="Transparent"
+                                            BorderThickness="0"
+                                            Command="{Binding DataContext.CloseTab}"
+                                            CommandParameter="{Binding}"
+                                            Content="X" />
                                     </Grid>
                                 </Border>
                             </Grid>
@@ -124,8 +135,10 @@
         <dragablz:TabablzControl
             Name="PDFViewerTab"
             Grid.RowSpan="2"
+            prism:RegionManager.RegionName="{x:Static cus:RegionNames.MainRegion}"
             BorderThickness="0"
             ItemContainerStyle="{StaticResource DragablzItemStyle}"
+            SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
             WindowChrome.IsHitTestVisibleInChrome="True">
             <dragablz:TabablzControl.InterTabController>
                 <dragablz:InterTabController />
@@ -139,7 +152,7 @@
                     HorizontalAlignment="Left"
                     Background="Transparent"
                     BorderThickness="0"
-                    Click="BtnAdd_Click"
+                    Command="{Binding AddTab}"
                     Content="+" />
             </dragablz:TabablzControl.HeaderSuffixContent>
             <dragablz:TabablzControl.HeaderPrefixContent>
@@ -149,16 +162,11 @@
                     Margin="0,2,0,0"
                     Background="Transparent" />
             </dragablz:TabablzControl.HeaderPrefixContent>
-            <TabItem Name="HomeTabControlItem">
-                <TabItem.Header>
-                    <DockPanel Height="40" VerticalAlignment="Center">
-                        <TextBlock Text="Home" />
-                    </DockPanel>
-                </TabItem.Header>
+            <!--<TabItem Name="HomeTabControlItem">
                 <TabItem.Content>
                     <ContentControl prism:RegionManager.RegionName="ViwerRegion" />
                 </TabItem.Content>
-            </TabItem>
+            </TabItem>-->
         </dragablz:TabablzControl>
 
         <!--  标题栏右侧栏,关闭按钮,会员,试用等  -->

+ 6 - 8
PDF Office/Views/MainWindow.xaml.cs

@@ -23,18 +23,11 @@ namespace PDF_Office.Views
     public partial class MainWindow : Window
     {
         public HomeContentViewModel HomeViewModel;
-        public MainWindow(IRegionManager regionManager)
+        public MainWindow()
         {
             InitializeComponent();
         }
 
-        private void BtnAdd_Click(object sender, RoutedEventArgs e)
-        {
-            TabItem tabItem = new TabItem();
-            tabItem.Header = "Test";
-            PDFViewerTab.Items.Add(tabItem);
-        }
-
         private void BtnMiniSize_Click(object sender, RoutedEventArgs e)
         {
             System.Windows.SystemCommands.MinimizeWindow(this);
@@ -52,5 +45,10 @@ namespace PDF_Office.Views
             else
                 System.Windows.SystemCommands.MaximizeWindow(this);
         }
+
+        private void Window_Activated(object sender, EventArgs e)
+        {
+            App.Current.MainWindow = this;
+        }
     }
 }

+ 134 - 6
PDF Office/Views/ViewContent.xaml

@@ -12,16 +12,139 @@
     d:DesignWidth="800"
     prism:ViewModelLocator.AutoWireViewModel="True"
     mc:Ignorable="d">
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <Style x:Key="TabControlWithUnderLineStyle" TargetType="{x:Type TabControl}">
+                <Setter Property="Padding" Value="2" />
+                <Setter Property="HorizontalContentAlignment" Value="Center" />
+                <Setter Property="VerticalContentAlignment" Value="Center" />
+                <Setter Property="Background" Value="Transparent" />
+                <Setter Property="BorderBrush" Value="#FFACACAC" />
+                <Setter Property="BorderThickness" Value="0,0,0,1" />
+                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
+                <Setter Property="Template">
+                    <Setter.Value>
+                        <ControlTemplate TargetType="{x:Type TabControl}">
+                            <Grid
+                                x:Name="templateRoot"
+                                ClipToBounds="True"
+                                KeyboardNavigation.TabNavigation="Local"
+                                SnapsToDevicePixels="True">
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition x:Name="ColumnDefinition0" />
+                                    <ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
+                                </Grid.ColumnDefinitions>
+                                <Grid.RowDefinitions>
+                                    <RowDefinition x:Name="RowDefinition0" Height="Auto" />
+                                    <RowDefinition x:Name="RowDefinition1" Height="*" />
+                                </Grid.RowDefinitions>
+                                <!--  加滑轨配合滑轨样式可实现箭头左右滚动的菜单栏  -->
+                                <!--<ScrollViewer  Margin="140 0 140 0" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">-->
+                                <TabPanel
+                                    x:Name="HeaderPanel"
+                                    Grid.Row="0"
+                                    Grid.Column="0"
+                                    Margin="30,0"
+                                    HorizontalAlignment="Center"
+                                    Panel.ZIndex="1"
+                                    Background="Transparent"
+                                    IsItemsHost="True"
+                                    KeyboardNavigation.TabIndex="1" />
+                                <!--</ScrollViewer>-->
+                                <!--  页头和中间内容的分割线  -->
+                                <Line
+                                    Margin="0,0,0,1"
+                                    VerticalAlignment="Bottom"
+                                    SnapsToDevicePixels="True"
+                                    Stroke="Transparent"
+                                    StrokeThickness="0.1"
+                                    X1="0"
+                                    X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
+                                <Border
+                                    x:Name="ContentPanel"
+                                    Grid.Row="1"
+                                    Grid.Column="0"
+                                    Background="{TemplateBinding Background}"
+                                    BorderBrush="{TemplateBinding BorderBrush}"
+                                    BorderThickness="{TemplateBinding BorderThickness}"
+                                    KeyboardNavigation.DirectionalNavigation="Contained"
+                                    KeyboardNavigation.TabIndex="2"
+                                    KeyboardNavigation.TabNavigation="Local">
+                                    <ContentPresenter
+                                        x:Name="PART_SelectedContentHost"
+                                        Margin="0"
+                                        Content="{TemplateBinding SelectedContent}"
+                                        ContentSource="SelectedContent"
+                                        ContentStringFormat="{TemplateBinding SelectedContentStringFormat}"
+                                        ContentTemplate="{TemplateBinding SelectedContentTemplate}"
+                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
+                                </Border>
+                            </Grid>
+                            <ControlTemplate.Triggers>
+                                <Trigger Property="TabStripPlacement" Value="Bottom">
+                                    <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="1" />
+                                    <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
+                                    <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
+                                    <Setter TargetName="RowDefinition1" Property="Height" Value="Auto" />
+
+                                </Trigger>
+                                <Trigger Property="TabStripPlacement" Value="Left">
+                                    <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
+                                    <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
+                                    <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="0" />
+                                    <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
+                                    <Setter TargetName="ColumnDefinition0" Property="Width" Value="Auto" />
+                                    <Setter TargetName="ColumnDefinition1" Property="Width" Value="*" />
+                                    <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
+                                    <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
+
+                                </Trigger>
+                                <Trigger Property="TabStripPlacement" Value="Right">
+                                    <Setter TargetName="HeaderPanel" Property="Grid.Row" Value="0" />
+                                    <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
+                                    <Setter TargetName="HeaderPanel" Property="Grid.Column" Value="1" />
+                                    <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
+                                    <Setter TargetName="ColumnDefinition0" Property="Width" Value="*" />
+                                    <Setter TargetName="ColumnDefinition1" Property="Width" Value="Auto" />
+                                    <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
+                                    <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
+                                </Trigger>
+                                <Trigger Property="IsEnabled" Value="False">
+                                    <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
+                                </Trigger>
+                            </ControlTemplate.Triggers>
+                        </ControlTemplate>
+                    </Setter.Value>
+                </Setter>
+                <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Cycle" />
+                <Setter Property="KeyboardNavigation.TabNavigation" Value="Cycle" />
+            </Style>
+        </ResourceDictionary>
+    </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Name="HeadRow" Height="40" />
             <RowDefinition Name="ToolRow" Height="40" />
             <RowDefinition Height="*" />
+            <RowDefinition Height="24" />
         </Grid.RowDefinitions>
+        <TabControl
+            x:Name="ToolTabControl"
+            Grid.Row="0"
+            Grid.RowSpan="2"
+            VerticalAlignment="Top"
+            BorderThickness="0"
+            Style="{StaticResource TabControlWithUnderLineStyle}">
+            <TabItem Header="Tool">
+                <Grid Grid.Row="1" Height="20" />
+            </TabItem>
+            <TabItem Header="Page Edit" />
+            <TabItem Header="Form" />
+        </TabControl>
         <Grid Name="DocumentView" Grid.Row="2">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition x:Name="BOTACloumn" Width="40" />
-                <ColumnDefinition Width="12" />
+                <ColumnDefinition Width="12" MaxWidth="400" />
                 <ColumnDefinition
                     Name="ViewerColumn"
                     Width="*"
@@ -29,15 +152,20 @@
                 <ColumnDefinition Width="12" />
                 <ColumnDefinition Name="PropertyColumn" Width="0" />
             </Grid.ColumnDefinitions>
-            <Grid.RowDefinitions>
-                <RowDefinition Height="*" />
-                <RowDefinition Height="32" />
-            </Grid.RowDefinitions>
+            <ContentControl prism:RegionManager.RegionName="{Binding BOTARegionName}" />
+            <GridSplitter
+                Grid.Column="1"
+                Width="12"
+                FocusVisualStyle="{x:Null}"
+                ResizeBehavior="PreviousAndNext"
+                ShowsPreview="True" />
             <ContentControl
                 x:Name="PDFViewerContent"
                 Grid.Column="2"
                 HorizontalAlignment="Stretch"
-                prism:RegionManager.RegionName="PDFViewer" />
+                prism:RegionManager.RegionName="{Binding ViwerRegionName}" />
+            <Button Grid.Column="3" />
+            <ContentControl Grid.Column="4" prism:RegionManager.RegionName="{Binding PropertyRegionName}" />
         </Grid>
     </Grid>
 </UserControl>

+ 0 - 5
PDF Office/Views/ViewContent.xaml.cs

@@ -24,11 +24,6 @@ namespace PDF_Office.Views
     /// </summary>
     public partial class ViewContent : UserControl
     {
-        /// <summary>
-        /// 因为XAML自动匹配VM的形式,会出现VM已经初始化,但是容器尚未加载完成的情况,
-        /// 因此此处采用特殊的形式,通过后台代码绑定VM
-        /// </summary>
-        private ViewContentViewModel contentViewModel;
         public ViewContent()
         {
             InitializeComponent();