Browse Source

BOTA搜索- 添加搜索功能

chenrongqian 2 years ago
parent
commit
ef465e5736

+ 49 - 16
PDF Office/ViewModels/BOTA/SearchContentViewModel.cs

@@ -18,10 +18,14 @@ using System.Windows.Threading;
 
 namespace PDF_Office.ViewModels.BOTA
 {
-     class SearchContentViewModel : BindableBase, INavigationAware
+
+    class SearchContentViewModel : BindableBase, INavigationAware
     {
+
+        #region 属性
+
         public PDFTextSearch textSearch;
-        private ObservableCollection<TextSearchBindItem> _searchResults = new /*ObservableCollection*/ObservableCollection<TextSearchBindItem>();
+        private ObservableCollection<TextSearchBindItem> _searchResults = new ObservableCollection<TextSearchBindItem>();
 
         public ObservableCollection<TextSearchBindItem> searchResults
         {
@@ -29,9 +33,37 @@ namespace PDF_Office.ViewModels.BOTA
             set { SetProperty(ref _searchResults, value); }
         }
         public List<TextSearchBindItem> lists;
+
+        private string _searchContent = "";
+        public string SearchContent
+        {
+            get { return _searchContent; }
+            set { SetProperty(ref _searchContent, value); }
+        }
+
+
+        private int _searchCount = 0;
+        public int SearchCount
+        {
+            get { return _searchCount; }
+            set { SetProperty(ref _searchCount, value); }
+        }
+
+        private bool _isEmpty = true;
+        public bool IsEmpty
+        {
+            get { return _isEmpty; }
+            set { SetProperty(ref _isEmpty, value); }
+        }
+
+        #endregion
+        #region  事件
         public DelegateCommand<object> SearchTextCommand { get; set; }
         public DelegateCommand<object> SearchChangedCommand { get; set; }
-        
+
+        #endregion
+
+
         public SearchContentViewModel()
         {
            InitVariable();
@@ -63,24 +95,23 @@ namespace PDF_Office.ViewModels.BOTA
         private void TextSearch_SearchCompletedHandler(object sender, TextSearchResult e)
         {
             issearched = true;
+            TotalCount = e.TotalCount;
         }
         bool issearched = true;
+        int TotalCount = 0;
         private bool cancelTask = false;
         private void TextSearch_SearchPercentHandler(object sender, TextSearchResult e)
         {
 
             if (cancelTask == false)
             {
-                // EmptyPanel.Visibility = Visibility.Collapsed;
-                string keywords = "1";//SearchControlItem.GetSearchWords();
-                                      //PercentBar.Value = e.Percent;
+                string keywords = SearchContent;
                 if (e.Items.ContainsKey(e.CurrentPage))
                 {
                     {
                         TextSearchBindItem addItem = new TextSearchBindItem();
                         addItem.PageCount = e.Items[e.CurrentPage].Count;
                         addItem.ShowPageIndex = e.CurrentPage;
-                        // percentResults.Add(addItem);
                     }
                     {
                         foreach (TextSearchItem item in e.Items[e.CurrentPage])
@@ -95,13 +126,8 @@ namespace PDF_Office.ViewModels.BOTA
                             lists.Add(addItem);
                         }
                     }
-                    //foreach (TextSearchBindItem item in percentResults)
-                    //{
-                    //    item.PageMaxCount = e.PageMaxCount;
-                    //}
-
                 }
-                // TotalRecord.Text = e.TotalCount.ToString();
+              
             }
         }
 
@@ -111,18 +137,25 @@ namespace PDF_Office.ViewModels.BOTA
             if (PDFViewer != null && textSearch != null)
             {
                 issearched = false;
-                   C_Search_Options option = C_Search_Options.Search_Case_Insensitive;
+                C_Search_Options option = C_Search_Options.Search_Case_Insensitive;
                 textSearch.TextSearchDocument = PDFViewer.Document;
+
                 searchResults.Clear();
                 lists.Clear();
-                var sourceText = "1";
-                textSearch.SearchText(sourceText, option);
+
+                textSearch.SearchText(SearchContent, option);
             }
             while (issearched == false)
                 await Task.Delay(10);
 
             foreach (var item in lists)
                 searchResults.Add(item);
+
+            SearchCount = TotalCount;
+            if (TotalCount == 0)
+                IsEmpty = true;
+            else
+                IsEmpty = false;
         }
 
 

+ 38 - 16
PDF Office/Views/BOTA/SearchContent.xaml

@@ -10,15 +10,16 @@
              d:DataContext="{d:DesignInstance Type=bota:SearchContentViewModel}"
              xmlns:helper="clr-namespace:PDF_Office.Helper"
               xmlns:convert="clr-namespace:PDF_Office.DataConvert"
+             xmlns:customControl="clr-namespace:PDF_Office.CustomControl"
              xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
    
     <UserControl.Resources>
         <convert:WidthConvert x:Key="WidthConvert"/>
-        
-        
-        
+        <convert:BoolToVisible x:Key="BoolToVisible"/>
+        <convert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert"/>
+
         <Style x:Key="ListViewItemGraySelectStyle" TargetType="{x:Type ListViewItem}">
             <Setter Property="UIElement.SnapsToDevicePixels"
             Value="True" />
@@ -110,36 +111,49 @@
     </UserControl.Resources>
     <Grid Background="#F3F3F3" Width="200">
         <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
             <RowDefinition Height="auto"/>
             <RowDefinition Height="auto"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
 
-        <Grid Height="48" >
+        <Grid Height="48" Margin="10,0,10,0">
             <TextBlock Text="查找"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
-            <Button Content="完成" HorizontalAlignment="Right" VerticalAlignment="Center"/>
+            <Button Content="完成" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding SearchTextCommand}"/>
         </Grid>
 
-        <Grid Height="48"  Grid.Row="1">
-            <TextBox Width="150" HorizontalAlignment="Left"/>
+        <TextBox Grid.Row="1" Margin="0,0,0,10" Width="180" Height="32" HorizontalAlignment="Center" 
+               Text="{Binding SearchContent,Mode=TwoWay}"
+                 />
 
-            <Button Content="完成" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding SearchTextCommand}"/>
+        <Grid Grid.Row="2" Margin="10,0,10,0" Visibility="{Binding IsEmpty ,Converter={StaticResource InvertBoolToVisibleConvert}}">
+            <TextBlock  Margin="0,0,0,10"  Text="All Result" VerticalAlignment="Center" HorizontalAlignment="Left"/>
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
+                <TextBlock  Margin="0,0,0,10"  Text="Results:" VerticalAlignment="Center" HorizontalAlignment="Right"/>
+                <TextBlock x:Name="TbCount"  Margin="0,0,0,10"  Text="{Binding SearchCount}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
+            </StackPanel>
+            
         </Grid>
-
-        <Grid Grid.Row="2">
-            <ListView Grid.Row="1" Name="SearchResultList" VirtualizingPanel.IsVirtualizingWhenGrouping="True" 
-                      ItemsSource="{Binding searchResults,Mode=OneWay}"
-                              BorderThickness="0" ItemContainerStyle="{StaticResource ListViewItemGraySelectStyle}" 
+        <Grid Grid.Row="3">
+            <ListView  Name="SearchResultList" VirtualizingPanel.IsVirtualizingWhenGrouping="True" 
+                              ItemsSource="{Binding searchResults,Mode=OneWay}"
+                              BorderThickness="0" ItemContainerStyle="{StaticResource ListViewItemGraySelectStyle}"
+                              Visibility="{Binding IsEmpty ,Converter={StaticResource InvertBoolToVisibleConvert}}"
                               SelectionChanged="SearchResultList_SelectionChanged"
                               ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                 <ListView.GroupStyle>
                     <GroupStyle>
                         <GroupStyle.HeaderTemplate>
                             <DataTemplate>
-                                <StackPanel Background="#E2E3E6" Height="24">
-                                    <TextBlock Padding="0,4,12,4" VerticalAlignment="Stretch" TextAlignment="Center" HorizontalAlignment="Right" FontWeight="SemiBold" FontSize="12" Text="{Binding Name}" 
+                                <Grid Background="#E2E3E6" Height="24" >
+                                    <TextBlock Padding="0,4,12,4" VerticalAlignment="Stretch" TextAlignment="Center" HorizontalAlignment="Center" FontWeight="SemiBold" FontSize="12" Text="{Binding Name}" 
                                                         FontFamily="Segoe UI" Foreground="#666666 "/>
-                                </StackPanel>
+                                    <customControl:CustomIconToggleBtn x:Name="BtnExptend" Height="24" Click="BtnExptend_Click" 
+                                                                       HorizontalAlignment="Right"
+                                                                      Style="{StaticResource ToggleBtnViewModeStyle}">
+                                        <TextBlock Text="展开" VerticalAlignment="Center"/>
+                                    </customControl:CustomIconToggleBtn>
+                                </Grid>
                             </DataTemplate>
                         </GroupStyle.HeaderTemplate>
                         <GroupStyle.Panel>
@@ -174,5 +188,13 @@
                 </i:Interaction.Triggers>
             </ListView>
         </Grid>
+
+        <Grid Grid.Row="0" Grid.RowSpan="4" Visibility="{Binding IsEmpty ,Converter={StaticResource BoolToVisible}}">
+            <StackPanel VerticalAlignment="Center" >
+                <Rectangle Margin="0,0,0,10" Width="140" Height="140" Fill="#D9D9D9" />
+                <TextBlock Text="Clik the XXX button below to create a XXX" Foreground="#94989C" Width="180" FontFamily="SF Pro Text" LineHeight="22" FontSize="14" TextAlignment="Center" TextWrapping="Wrap"/>
+            </StackPanel>
+            
+        </Grid>
     </Grid>
 </UserControl>

+ 31 - 1
PDF Office/Views/BOTA/SearchContent.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using PDF_Office.CustomControl;
+using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
@@ -68,5 +69,34 @@ namespace PDF_Office.Views.BOTA
         {
 
         }
+
+        private void BtnExptend_Click(object sender, RoutedEventArgs e)
+        {
+            var btn = sender as CustomIconToggleBtn;
+            if (btn == null) return;
+
+
+            var item = (sender as FrameworkElement).DataContext as CollectionViewGroup;
+            if(item != null)
+            {
+                foreach (var item2 in item.Items)
+                {
+                    var item3 = item2 as TextSearchBindItem;
+
+                    var listBoxItem = SearchResultList.ItemContainerGenerator.ContainerFromItem(item3) as ListViewItem;
+                    if (listBoxItem != null)
+                    {
+                       if(btn.IsChecked == true)
+                        {
+                            listBoxItem.Visibility = Visibility.Collapsed;
+                        }
+                       else
+                        {
+                            listBoxItem.Visibility = Visibility.Visible;
+                        }
+                    }
+                }
+            }
+        }
     }
 }

+ 2 - 2
PDF Office/Views/HomePanel/PDFTools/QuickToolsContent.xaml.cs

@@ -78,7 +78,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
             foreach (var item in ListBoxToolBars.Items)
             {
                 i++;
-                var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
+               var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
                 if (listBoxItem != null)
                 {
                     if (i % 4 != 0)
@@ -91,7 +91,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
                         listBoxItem.Margin = new Thickness(0, 0, 0, 0);
                     }
                     listBoxItem.Width = widthItem;
-                }
+                } 
             }
         }