Browse Source

页眉页脚

liyijie 2 years ago
parent
commit
f794813983

+ 1 - 1
PDF Office/Helper/EditToolsHelper.cs

@@ -36,10 +36,10 @@ namespace PDF_Office.Helper
         public static Color ConvertColor(byte[] rgb_array)
         {
             Color color = new Color();
+            color.A = 0xFF;
             color.R = rgb_array[0];
             color.G = rgb_array[1];
             color.B = rgb_array[2];
-
             return color;
         }
 

+ 8 - 6
PDF Office/ViewModels/EditTools/Bates/BatesCreateContentViewModel.cs

@@ -144,11 +144,6 @@ namespace PDF_Office.ViewModels.EditTools.Bates
             {
                 SetProperty(ref _starPagetNumberIndex, value);
                 SetStarPagetNumber(StarPagetNumberIndex);
-                eventAggregator.GetEvent<SetBatesEvent>().Publish(new BatesInfoUnicode
-                {
-                    Unicode = Unicode,
-                    Status = BatesInfo
-                });
             }
         }
 
@@ -609,12 +604,18 @@ namespace PDF_Office.ViewModels.EditTools.Bates
                 GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + "#" + DigitNumberValue + "#" + (StarPagetNumberIndex + 1).ToString() + "#" + PrefixTextValue + "#" + SurfixTextValue + ">>";
             }
             BatesInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
+            eventAggregator.GetEvent<SetBatesEvent>().Publish(new BatesInfoUnicode
+            {
+                Unicode = Unicode,
+                Status = BatesInfo
+            });
         }
 
         public void ConvertInfoToItem(ref BatesHeaderFooterItem batesItem, BatesInfo batesInfo)
         {
             batesItem.TextData = batesInfo.TextData;
             batesItem.DigitNumber = batesInfo.DigitNumber;
+            batesItem.ItemName = batesInfo.ItemName;
             batesItem.Prefix = batesInfo.Prefix;
             batesItem.Suffix = batesInfo.Suffix;
             batesItem.StarPagetNumber = batesInfo.StarPagetNumber;
@@ -627,6 +628,7 @@ namespace PDF_Office.ViewModels.EditTools.Bates
         public void ConvertItemToInfo(BatesHeaderFooterItem batesItem, ref BatesInfo batesInfo)
         {
             batesInfo.TextData = batesItem.TextData;
+            batesInfo.ItemName = batesItem.ItemName;
             batesInfo.DigitNumber = batesItem.DigitNumber;
             batesInfo.Prefix = batesItem.Prefix;
             batesInfo.Suffix = batesItem.Suffix;
@@ -641,7 +643,7 @@ namespace PDF_Office.ViewModels.EditTools.Bates
         {
             var batesItem = new BatesHeaderFooterItem();
             ConvertInfoToItem(ref batesItem, BatesInfo);
-            batesItem.ItemName += Settings.Default.WatermarkIndex.ToString();
+            batesItem.ItemName += Settings.Default.BatesTemplateList.Count().ToString();
             try
             {
                 //创建缓存文件夹

+ 1 - 0
PDF Office/ViewModels/EditTools/Bates/BatesTemplateListContentViewModel.cs

@@ -196,6 +196,7 @@ namespace PDF_Office.ViewModels.EditTools.Bates
         public void ConvertItemToInfo(BatesHeaderFooterItem batesItem, ref BatesInfo batesInfo)
         {
             batesInfo.TextData = batesItem.TextData;
+            batesInfo.ItemName = batesItem.ItemName;
             batesInfo.DigitNumber = batesItem.DigitNumber;
             batesInfo.Prefix=batesItem.Prefix;
             batesInfo.Suffix=batesItem.Suffix;

+ 0 - 1
PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterContentViewModel.cs

@@ -128,7 +128,6 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
         {
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.PDFViewer, PDFViewer);
-           
             headerFooterRegion.RequestNavigate(HeaderFooterSettingsRegionName, SelectedContentName, param);
             HeaderFooterSettingsVisible = Visibility.Visible;
         }

+ 37 - 33
PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterCreateContentViewModel.cs

@@ -20,6 +20,7 @@ using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.EditTools.HeaderFooter
@@ -181,11 +182,6 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
             {
                 SetProperty(ref _pageNumberFormatIndex, value);
                 SetPageNumberFormat(PageNumberFormatIndex);
-                eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
-                {
-                    Unicode = Unicode,
-                    Status = HeaderFooterInfo
-                });
             }
         }
 
@@ -196,12 +192,6 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
             set
             {
                 SetProperty(ref _dateTimeFormatList, value);
-                SetDateTimeFormat(DateTimeFormatIndex);
-                eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
-                {
-                    Unicode = Unicode,
-                    Status = HeaderFooterInfo
-                });
             }
         }
 
@@ -240,11 +230,6 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
             {
                 SetProperty(ref _dateTimeFormatIndex, value);
                 SetDateTimeFormat(DateTimeFormatIndex);
-                eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
-                {
-                    Unicode = Unicode,
-                    Status = HeaderFooterInfo
-                });
             }
         }
 
@@ -610,8 +595,9 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
                 var textValue = obj as System.Windows.Controls.TextBox;
                 if (textValue != null)
                 {
-                    bool TextEQ=true;
-                    if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text) {
+                    bool TextEQ = true;
+                    if (GetTextValueFromNumber[GetLocationIndex.ToString()] == textValue.Text)
+                    {
                         TextEQ = false;
                     }
                     GetTextValueFromNumber[GetLocationIndex.ToString()] = textValue.Text;
@@ -624,48 +610,65 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
                             Status = HeaderFooterInfo
                         });
                     }
-                   
+
                 }
             }
 
         }
 
-        public void ADDDate() {
-            GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<"+DateTimeFormatList[DateTimeFormatIndex]+">>";
+        public void ADDDate()
+        {
+            GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + DateTimeFormatList[DateTimeFormatIndex] + ">>";
             TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
+            HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
+            eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
+            {
+                Unicode = Unicode,
+                Status = HeaderFooterInfo
+            });
         }
-        public void ADDPages() {
+        public void ADDPages()
+        {
             GetTextValueFromNumber[GetLocationIndex.ToString()] = GetTextValueFromNumber[GetLocationIndex.ToString()] + "<<" + PageNumberFormatList[PageNumberFormatIndex] + ">>";
             TextValue = GetTextValueFromNumber[GetLocationIndex.ToString()];
+            HeaderFooterInfo.TextData[GetLocationIndex].text = GetTextValueFromNumber[GetLocationIndex.ToString()];
+            eventAggregator.GetEvent<SetHeaderFooterEvent>().Publish(new HeaderFooterInfoUnicode
+            {
+                Unicode = Unicode,
+                Status = HeaderFooterInfo
+            });
         }
 
         public void ConvertInfoToItem(ref BatesHeaderFooterItem headerFooterItem, HeaderFooterInfo headerFooterInfo)
         {
-           headerFooterItem.TextData = headerFooterInfo.TextData ;
-           headerFooterItem.DateTimeFormat =  headerFooterInfo.DateTimeFormat;
-           headerFooterItem.StarPagetNumber=  headerFooterInfo.StarPagetNumber ;
-           headerFooterItem.PageNumberFormat= headerFooterInfo.PageNumberFormat  ;
-           headerFooterItem.margin= headerFooterInfo.margin  ;
-           headerFooterItem.PageRange=  headerFooterInfo.PageRange ;
-           headerFooterItem.PageRangeIndex=  headerFooterInfo.PageRangeIndex ;
+            headerFooterItem.TextData = headerFooterInfo.TextData;
+            headerFooterItem.ItemName = headerFooterInfo.ItemName;
+            headerFooterItem.DateTimeFormat = headerFooterInfo.DateTimeFormat;
+            headerFooterItem.StarPagetNumber = headerFooterInfo.StarPagetNumber;
+            headerFooterItem.PageNumberFormat = headerFooterInfo.PageNumberFormat;
+            headerFooterItem.margin = headerFooterInfo.margin;
+            headerFooterItem.PageRange = headerFooterInfo.PageRange;
+            headerFooterItem.PageRangeIndex = headerFooterInfo.PageRangeIndex;
         }
 
         public void ConvertItemToInfo(BatesHeaderFooterItem headerFooterItem, ref HeaderFooterInfo headerFooterInfo)
         {
             headerFooterInfo.TextData = headerFooterItem.TextData;
+            headerFooterInfo.ItemName = headerFooterItem.ItemName;
             headerFooterInfo.DateTimeFormat = headerFooterItem.DateTimeFormat;
             headerFooterInfo.StarPagetNumber = headerFooterItem.StarPagetNumber;
             headerFooterInfo.PageNumberFormat = headerFooterItem.PageNumberFormat;
             headerFooterInfo.margin = headerFooterItem.margin;
-            headerFooterInfo.PageRange = headerFooterItem.PageRange;
             headerFooterInfo.PageRangeIndex = headerFooterItem.PageRangeIndex;
+            EditToolsHelper.GetPageRange(headerFooterInfo.PageRangeIndex, PDFViewer.Document, ref headerFooterInfo.PageRange, headerFooterItem.PageRange);
         }
 
         public void SaveCurrentTemplate()
         {
             var headerFooterItem = new BatesHeaderFooterItem();
+
             ConvertInfoToItem(ref headerFooterItem, HeaderFooterInfo);
-            headerFooterItem.ItemName += Settings.Default.HeaderFooterIndex.ToString();
+            headerFooterItem.ItemName += Settings.Default.HeaderFooterTemplateList.Count().ToString();
             try
             {
                 //创建缓存文件夹
@@ -747,13 +750,14 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
             MarginRightValue = HeaderFooterInfo.margin[1].ToString();
             MarginDownValue = HeaderFooterInfo.margin[2].ToString();
             MarginLeftValue = HeaderFooterInfo.margin[3].ToString();
-            DateTimeFormatIndex=DateTimeFormatList.IndexOf(HeaderFooterInfo.DateTimeFormat);
-            PageNumberFormatIndex=PageNumberFormatList.IndexOf(HeaderFooterInfo.PageNumberFormat);
+            DateTimeFormatIndex = DateTimeFormatList.IndexOf(HeaderFooterInfo.DateTimeFormat);
+            PageNumberFormatIndex = PageNumberFormatList.IndexOf(HeaderFooterInfo.PageNumberFormat);
             FontNameSelectedIndex = FontNameList.IndexOf(HeaderFooterInfo.TextData[0].fontName);
             FontSizeSelectedIndex = FontSizeList.IndexOf(HeaderFooterInfo.TextData[0].fontSize.ToString());
             StarPagetNumberIndex = StarPagetNumberList.IndexOf(HeaderFooterInfo.StarPagetNumber.ToString());
             StringColor = EditToolsHelper.ConvertColor(HeaderFooterInfo.TextData[0].Color);
             SolidColorBrush = new SolidColorBrush(StringColor);
+            PageRangeSelectIndex = HeaderFooterInfo.PageRangeIndex;
 
         }
 

+ 9 - 2
PDF Office/ViewModels/EditTools/HeaderFooter/HeaderFooterTemplateListContentViewModel.cs

@@ -1,4 +1,7 @@
-using PDF_Office.EventAggregators;
+using ComPDFKitViewer.PdfViewer;
+using PDF_Office.EventAggregators;
+using PDF_Office.Helper;
+using PDF_Office.Model;
 using PDF_Office.Model.EditTools.Bates;
 using PDF_Office.Model.EditTools.HeaderFooter;
 using PDF_Office.Properties;
@@ -19,6 +22,7 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
     public class HeaderFooterTemplateListContentViewModel : BindableBase, INavigationAware
     {
         public IEventAggregator eventAggregator;
+        private CPDFViewer PDFViewer;
         public HeaderFooterInfo HeaderFooterInfo = new HeaderFooterInfo();
         public BatesHeaderFooterItem HeaderFooterItem = new BatesHeaderFooterItem();
         public int TemplateIndex = 0;
@@ -189,12 +193,13 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
         public void ConvertItemToInfo(BatesHeaderFooterItem headerFooterItem, ref HeaderFooterInfo headerFooterInfo)
         {
             headerFooterInfo.TextData = headerFooterItem.TextData;
+            headerFooterInfo.ItemName=headerFooterItem.ItemName;
             headerFooterInfo.DateTimeFormat = headerFooterItem.DateTimeFormat;
             headerFooterInfo.StarPagetNumber = headerFooterItem.StarPagetNumber;
             headerFooterInfo.PageNumberFormat = headerFooterItem.PageNumberFormat;
             headerFooterInfo.margin = headerFooterItem.margin;
-            headerFooterInfo.PageRange = headerFooterItem.PageRange;
             headerFooterInfo.PageRangeIndex = headerFooterItem.PageRangeIndex;
+            EditToolsHelper.GetPageRange(headerFooterInfo.PageRangeIndex, PDFViewer.Document, ref headerFooterInfo.PageRange, headerFooterItem.PageRange);
         }
         private void CheckTemplateListIsEmpty(List<BatesHeaderFooterItem> headerFooterTemplateList)
         {
@@ -219,7 +224,9 @@ namespace PDF_Office.ViewModels.EditTools.HeaderFooter
 
         public void OnNavigatedTo(NavigationContext navigationContext)
         {
+            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             InitBackgroundTemplateList();
+           
         }
     }
 }

+ 101 - 101
PDF Office/Views/EditTools/Bates/BatesTemplateListContent.xaml

@@ -9,20 +9,20 @@
              mc:Ignorable="d"
              d:DesignHeight="720"
              d:DesignWidth="260" >
-    <UserControl.Resources>
-        <ContextMenu x:Key="FlyoutMenu" FontSize="14" >
-            <ContextMenu.ItemContainerStyle>
-                <Style TargetType="{x:Type MenuItem}">
-                    <Setter Property="Padding" Value="0,8,0,8"/>
-                    <Setter Property="VerticalContentAlignment" Value="Center"/>
-                </Style>
-            </ContextMenu.ItemContainerStyle>
-            <MenuItem Name="MenuEdit" Header="编辑模板" Click="MenuEdit_Click" >
-            </MenuItem>
-            <MenuItem Name="MenuDeleteCurrent" Header="删除模板"  Click="MenuDeleteCurrent_Click">
-            </MenuItem>
-            <MenuItem Name="MenuDeleteAll" Header="删除全部" Click="MenuDeleteAll_Click"></MenuItem>
-        </ContextMenu>
+    <UserControl.Resources>
+        <ContextMenu x:Key="FlyoutMenu" FontSize="14" >
+            <ContextMenu.ItemContainerStyle>
+                <Style TargetType="{x:Type MenuItem}">
+                    <Setter Property="Padding" Value="0,8,0,8"/>
+                    <Setter Property="VerticalContentAlignment" Value="Center"/>
+                </Style>
+            </ContextMenu.ItemContainerStyle>
+            <MenuItem Name="MenuEdit" Header="编辑模板" Click="MenuEdit_Click" >
+            </MenuItem>
+            <MenuItem Name="MenuDeleteCurrent" Header="删除模板"  Click="MenuDeleteCurrent_Click">
+            </MenuItem>
+            <MenuItem Name="MenuDeleteAll" Header="删除全部" Click="MenuDeleteAll_Click"></MenuItem>
+        </ContextMenu>
     </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>
@@ -36,93 +36,93 @@
                 <Button  Height="20" Width="20" Margin="16,0,16,0" Command="{Binding EnterCreateCommand}"></Button>
             </StackPanel>
         </Grid>
-        <Grid Background="#F3F3F3" Grid.Row="1">
-            <ListBox
-                                Width="260" 
-                                BorderThickness="0"
-                                ScrollViewer.CanContentScroll="True"
-                                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
-                                ScrollViewer.VerticalScrollBarVisibility="Hidden"
-                                VirtualizingPanel.IsVirtualizing="True"
-                                VirtualizingPanel.VirtualizationMode="Standard"
-                                VirtualizingPanel.CacheLengthUnit="Page"
-                                VirtualizingPanel.CacheLength="1"
-                                VirtualizingPanel.ScrollUnit="Pixel"   
-                                Background="#F3F3F3"
-                 ItemsSource="{Binding BatesModCollection}"  
-            SelectionChanged="ListBox_SelectionChanged">
-
-                <ListBox.ItemContainerStyle>
-                    <Style TargetType="ListBoxItem">
-                        <Setter Property="Margin" Value="11"/>
-                        <Setter Property="Padding" Value="0 0 0 0"/>
-                        <Setter Property="Width" Value="238"/>
-                        <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>
-                        <Setter Property="Template" Value="{DynamicResource EditToolsItemControlTemplate}"/>
-                    </Style>
-                </ListBox.ItemContainerStyle>
-                <ListBox.ItemTemplate>
-                    <DataTemplate DataType="{x:Type data:BatesHeaderFooterItem}">
-                        <StackPanel Name="itemPanel" Loaded="itemPanel_Loaded">
-                            <Border BorderThickness="1" BorderBrush="#A0A2AE">
-                                <Grid  Width="238" HorizontalAlignment="Left">
-                                    <StackPanel >
-                                        <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
-                                            <TextBlock Text="Bates名称" Height="22" Width="98" FontSize="14" FontWeight="Black"></TextBlock>
-                                            <TextBlock Name="TemplateIndexTextBox"  FontSize="14" ></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
-                                            <TextBlock Text="左侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="LeftHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22" ></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
-                                            <TextBlock Text="右侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="RightHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
-                                            <TextBlock Text="中间页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="CenterHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
-                                            <TextBlock Text="左侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="LeftFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
-                                            <TextBlock Text="右侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="RightFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
-                                        </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
-                                            <TextBlock Text="中间页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
-                                            <TextBlock Name="CenterFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
-                                        </StackPanel>
-                                        
-                                    </StackPanel>
-                                    <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="EditTemplateBtn_Click"></Button>
-                                    <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click">
-                                    </Button>
-                                </Grid>
-                            </Border>
-                        </StackPanel>
-                        <DataTemplate.Triggers>
-                            <Trigger Property="IsMouseOver" Value="True">
-                                <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Visible"/>
-                                <Setter TargetName="DeleteTemplateBtn" Property="Visibility" Value="Visible"/>
-                            </Trigger>
-                            <Trigger Property="IsMouseOver" Value="False">
-                                <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Collapsed"/>
-                                <Setter TargetName="DeleteTemplateBtn" Property="Visibility" Value="Collapsed"/>
-                            </Trigger>
-                        </DataTemplate.Triggers>
-                    </DataTemplate>
-                </ListBox.ItemTemplate>
-            </ListBox>
-            <Grid Width="140"  Margin="64,153,56,0" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
-                <StackPanel Orientation="Vertical">
-                    <Label Height="87" Width="87" HorizontalAlignment="Center" Background="BlueViolet"></Label>
-                    <TextBlock Height="24" FontSize="14" Text="请先创建一个Bates模板" Margin="0,8,0,0" VerticalAlignment="Center" ></TextBlock>
-                    <Button Height="24" Width="44" Margin="0,12,0,0" Content ="新建" Command="{Binding AddTemplateCommand}"></Button>
-                </StackPanel>
-            </Grid>
+        <Grid Background="#F3F3F3" Grid.Row="1">
+            <ListBox
+                                Width="260" 
+                                BorderThickness="0"
+                                ScrollViewer.CanContentScroll="True"
+                                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
+                                ScrollViewer.VerticalScrollBarVisibility="Hidden"
+                                VirtualizingPanel.IsVirtualizing="True"
+                                VirtualizingPanel.VirtualizationMode="Standard"
+                                VirtualizingPanel.CacheLengthUnit="Page"
+                                VirtualizingPanel.CacheLength="1"
+                                VirtualizingPanel.ScrollUnit="Pixel"   
+                                Background="#F3F3F3"
+                 ItemsSource="{Binding BatesModCollection}"  
+            SelectionChanged="ListBox_SelectionChanged">
+
+                <ListBox.ItemContainerStyle>
+                    <Style TargetType="ListBoxItem">
+                        <Setter Property="Margin" Value="11"/>
+                        <Setter Property="Padding" Value="0 0 0 0"/>
+                        <Setter Property="Width" Value="238"/>
+                        <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"/>
+                        <Setter Property="Template" Value="{DynamicResource EditToolsItemControlTemplate}"/>
+                    </Style>
+                </ListBox.ItemContainerStyle>
+                <ListBox.ItemTemplate>
+                    <DataTemplate DataType="{x:Type data:BatesHeaderFooterItem}">
+                        <StackPanel Name="itemPanel" Loaded="itemPanel_Loaded">
+                            <Border BorderThickness="1" BorderBrush="#A0A2AE">
+                                <Grid  Width="238" HorizontalAlignment="Left">
+                                    <StackPanel >
+                                        <StackPanel Orientation="Horizontal" Margin="0,12,0,0">
+                                            <TextBlock Text="页眉页脚名称" Height="22" Width="98" FontSize="14" FontWeight="Black"></TextBlock>
+                                            <TextBlock Name="TemplateIndexTextBox"  FontSize="14" ></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,8,0,0" Visibility="{Binding ElementName=LeftHeaderTextBox,Path=Visibility}">
+                                            <TextBlock Text="左侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="LeftHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22" ></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=RightHeaderTextBox,Path=Visibility}">
+                                            <TextBlock Text="右侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="RightHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=CenterHeaderTextBox,Path=Visibility}">
+                                            <TextBlock Text="中间页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="CenterHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=LeftFooterTextBox,Path=Visibility}">
+                                            <TextBlock Text="左侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="LeftFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=RightFooterTextBox,Path=Visibility}">
+                                            <TextBlock Text="右侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="RightFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
+                                        </StackPanel>
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=CenterFooterTextBox,Path=Visibility}">
+                                            <TextBlock Text="中间页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
+                                            <TextBlock Name="CenterFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
+                                        </StackPanel>
+
+                                    </StackPanel>
+                                    <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="EditTemplateBtn_Click"></Button>
+                                    <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click">
+                                    </Button>
+                                </Grid>
+                            </Border>
+                        </StackPanel>
+                        <DataTemplate.Triggers>
+                            <Trigger Property="IsMouseOver" Value="True">
+                                <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Visible"/>
+                                <Setter TargetName="DeleteTemplateBtn" Property="Visibility" Value="Visible"/>
+                            </Trigger>
+                            <Trigger Property="IsMouseOver" Value="False">
+                                <Setter TargetName="EditTemplateBtn" Property="Visibility" Value="Collapsed"/>
+                                <Setter TargetName="DeleteTemplateBtn" Property="Visibility" Value="Collapsed"/>
+                            </Trigger>
+                        </DataTemplate.Triggers>
+                    </DataTemplate>
+                </ListBox.ItemTemplate>
+            </ListBox>
+            <Grid Width="140"  Margin="64,153,56,0" Visibility="{Binding CreateTemplateVisible, Mode=OneWay}">
+                <StackPanel Orientation="Vertical">
+                    <Label Height="87" Width="87" HorizontalAlignment="Center" Background="BlueViolet"></Label>
+                    <TextBlock Height="24" FontSize="14" Text="请先创建一个Bates模板" Margin="0,8,0,0" VerticalAlignment="Center" ></TextBlock>
+                    <Button Height="24" Width="44" Margin="0,12,0,0" Content ="新建" Command="{Binding AddTemplateCommand}"></Button>
+                </StackPanel>
+            </Grid>
         </Grid>
     </Grid>
 </UserControl>

+ 8 - 6
PDF Office/Views/EditTools/Bates/BatesTemplateListContent.xaml.cs

@@ -7,6 +7,7 @@ using System;
 using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 using System.IO;
+using System.Collections.Generic;
 
 namespace PDF_Office.Views.EditTools.Bates
 {
@@ -67,15 +68,16 @@ namespace PDF_Office.Views.EditTools.Bates
                 var LeftFooter = panel.FindName("LeftFooterTextBox") as TextBlock;
                 var RightFooter = panel.FindName("RightFooterTextBox") as TextBlock;
                 var CenterFooter = panel.FindName("CenterFooterTextBox") as TextBlock;
+                List<TextBlock> textBlocks = new List<TextBlock>() { LeftHeader, RightHeader, CenterHeader, LeftFooter, RightFooter, CenterFooter };
                 if (data.TextData != null)
                 {
                     TemplateIndex.Text = data.ItemName;
-                    LeftHeader.Text = data.TextData[0].text;
-                    RightHeader.Text = data.TextData[2].text;
-                    CenterHeader.Text = data.TextData[1].text;
-                    LeftFooter.Text = data.TextData[3].text;
-                    RightFooter.Text = data.TextData[5].text;
-                    CenterFooter.Text = data.TextData[4].text;
+                    foreach (var textBlock in textBlocks)
+                    {
+                        textBlock.Text = data.TextData[textBlocks.IndexOf(textBlock)].text;
+                        if (textBlock.Text == "") { textBlock.Visibility = Visibility.Collapsed; }
+                        else { textBlock.Visibility = Visibility.Visible; }
+                    }
                 }
             }
             catch { }

+ 6 - 6
PDF Office/Views/EditTools/HeaderFooter/HeaderFooterTemplateListContent.xaml

@@ -71,27 +71,27 @@
                                             <TextBlock Text="页眉页脚名称" Height="22" Width="98" FontSize="14" FontWeight="Black"></TextBlock>
                                             <TextBlock Name="TemplateIndexTextBox"  FontSize="14" ></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,8,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,8,0,0" Visibility="{Binding ElementName=LeftHeaderTextBox,Path=Visibility}">
                                             <TextBlock Text="左侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="LeftHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22" ></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=RightHeaderTextBox,Path=Visibility}">
                                             <TextBlock Text="右侧页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="RightHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=CenterHeaderTextBox,Path=Visibility}">
                                             <TextBlock Text="中间页眉:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="CenterHeaderTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=LeftFooterTextBox,Path=Visibility}">
                                             <TextBlock Text="左侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="LeftFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=RightFooterTextBox,Path=Visibility}">
                                             <TextBlock Text="右侧页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="RightFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
                                         </StackPanel>
-                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
+                                        <StackPanel Orientation="Horizontal" Margin="0,4,0,0" Visibility="{Binding ElementName=CenterFooterTextBox,Path=Visibility}">
                                             <TextBlock Text="中间页脚:"  FontSize="14" Height="22" Width="70"></TextBlock>
                                             <TextBlock Name="CenterFooterTextBox"  FontSize="14" Margin="8,0,0,0" Width="149" Height="22"></TextBlock>
                                         </StackPanel>

+ 7 - 6
PDF Office/Views/EditTools/HeaderFooter/HeaderFooterTemplateListContent.xaml.cs

@@ -7,6 +7,7 @@ using System;
 using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 using System.IO;
+using System.Collections.Generic;
 
 namespace PDF_Office.Views.EditTools.HeaderFooter
 {
@@ -69,15 +70,15 @@ namespace PDF_Office.Views.EditTools.HeaderFooter
                 var LeftFooter = panel.FindName("LeftFooterTextBox") as TextBlock;
                 var RightFooter = panel.FindName("RightFooterTextBox") as TextBlock;
                 var CenterFooter = panel.FindName("CenterFooterTextBox") as TextBlock;
+                List<TextBlock> textBlocks=new List<TextBlock>() { LeftHeader, RightHeader, CenterHeader , LeftFooter , RightFooter , CenterFooter };
                 if (data.TextData != null)
                 {
                     TemplateIndex.Text = data.ItemName;
-                    LeftHeader.Text = data.TextData[0].text;
-                    RightHeader.Text = data.TextData[2].text;
-                    CenterHeader.Text = data.TextData[1].text;
-                    LeftFooter.Text = data.TextData[3].text;
-                    RightFooter.Text = data.TextData[5].text;
-                    CenterFooter.Text = data.TextData[4].text;
+                    foreach (var textBlock in textBlocks) {
+                        textBlock.Text = data.TextData[textBlocks.IndexOf(textBlock)].text;
+                        if (textBlock.Text == "") { textBlock.Visibility = Visibility.Collapsed; }
+                        else { textBlock.Visibility = Visibility.Visible; }
+                    }
                 }
             }
             catch { }