Selaa lähdekoodia

bota 书签 多选 单选右键菜单的问题

OYXH\oyxh 1 vuosi sitten
vanhempi
commit
91d7e35e0e

+ 64 - 0
PDF Office/Styles/ListViewStyle.xaml

@@ -403,6 +403,70 @@
         </Setter>
     </Style>
 
+    <Style x:Key="ListBoxItemGraySelectStyle" TargetType="{x:Type ListBoxItem}">
+        <Setter Property="UIElement.SnapsToDevicePixels" Value="True" />
+        <Setter Property="Panel.Background" Value="{StaticResource color.sys.layout.mg}" />
+        <Setter Property="Border.BorderBrush" Value="{StaticResource color.sys.layout.mg}" />
+        <Setter Property="Margin" Value="8,0" />
+        <Setter Property="Control.Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="{x:Type ListBoxItem}">
+                    <Border
+                        Name="Bd"
+                        Background="{TemplateBinding Panel.Background}"
+                        BorderBrush="{TemplateBinding Border.BorderBrush}"
+                        BorderThickness="1"
+                        CornerRadius="4"
+                        SnapsToDevicePixels="True">
+                        <ContentPresenter
+                            Margin="0"
+                            HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
+                            VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
+                            Content="{TemplateBinding ContentControl.Content}"
+                            ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
+                            ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
+                            SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
+                    </Border>
+                    <ControlTemplate.Triggers>
+                        <MultiTrigger>
+                            <MultiTrigger.Conditions>
+                                <Condition Property="UIElement.IsMouseOver" Value="True" />
+                            </MultiTrigger.Conditions>
+                            <Setter Property="Panel.Background" Value="{StaticResource color.item-state.hov.bg}" />
+                            <Setter Property="Border.BorderBrush" Value="{StaticResource color.item-state.hov.bg}" />
+                        </MultiTrigger>
+                        <!--<MultiTrigger>
+                        <MultiTrigger.Conditions>
+                        <Condition Property="UIElement.IsMouseOver" Value="False" />
+                        </MultiTrigger.Conditions>
+                        <Setter Property="Panel.Background" Value="#F2F2F2" />
+                        <Setter Property="Border.BorderBrush" Value="#F2F2F2" />
+                        </MultiTrigger>-->
+                        <MultiTrigger>
+                            <MultiTrigger.Conditions>
+                                <Condition Property="Selector.IsSelectionActive" Value="False" />
+                                <Condition Property="Selector.IsSelected" Value="True" />
+                            </MultiTrigger.Conditions>
+                            <Setter Property="Panel.Background" Value="{StaticResource color.item-state.sel.bg.lv3}" />
+                            <Setter Property="Border.BorderBrush" Value="{StaticResource color.item-state.sel.border.lv3}" />
+                        </MultiTrigger>
+
+                        <MultiTrigger>
+                            <MultiTrigger.Conditions>
+                                <Condition Property="Selector.IsSelectionActive" Value="True" />
+                                <Condition Property="Selector.IsSelected" Value="True" />
+                            </MultiTrigger.Conditions>
+                            <Setter Property="Panel.Background" Value="{StaticResource color.item-state.sel.bg.lv3}" />
+                            <Setter Property="Border.BorderBrush" Value="{StaticResource color.item-state.sel.border.lv3}" />
+                        </MultiTrigger>
+                        <!--<Trigger Property="UIElement.IsEnabled" Value="False">
+                        <Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
+                        </Trigger>-->
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
     <ControlTemplate x:Key="AnnotationListItemStyle" TargetType="{x:Type ListBoxItem}">
         <Border
             x:Name="Bd"

+ 7 - 7
PDF Office/ViewModels/BOTA/BookmarkContentViewModel.cs

@@ -255,7 +255,7 @@ namespace PDF_Master.ViewModels.BOTA
                     if (keyEventArgs.OriginalSource is TextBox)
                     {
                         TextBox textBox = (TextBox)keyEventArgs.OriginalSource;
-                        ListViewItem listViewItem = CommonHelper.FindVisualParent<ListViewItem>(textBox);
+                        ListBoxItem listViewItem = CommonHelper.FindVisualParent<ListBoxItem>(textBox);
                         UpdateTitle(listViewItem, textBox);
                         TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(listViewItem);
                         textBlock.Text = textBox.Text;
@@ -368,7 +368,7 @@ namespace PDF_Master.ViewModels.BOTA
         /// </summary>
         /// <param name="listViewItem"></param>
         /// <param name="textBox"></param>
-        private void UpdateTitle(ListViewItem listViewItem, TextBox textBox)
+        private void UpdateTitle(ListBoxItem listViewItem, TextBox textBox)
         {
             if (listViewItem != null)
             {
@@ -415,7 +415,7 @@ namespace PDF_Master.ViewModels.BOTA
             int index = PDFViewer.CurrentIndex;
             string mark = string.Format(info, (index + 1).ToString());
 
-            System.Windows.Controls.ListView listView = obj as System.Windows.Controls.ListView;
+            System.Windows.Controls.ListBox listView = obj as System.Windows.Controls.ListBox;
             listView.SelectedItems.Clear();
             IsHasBookmark = IsExistBookmark(listView);// await Task.Run(() => IsExistBookmark(listView));
             if (IsHasBookmark == false)
@@ -470,7 +470,7 @@ namespace PDF_Master.ViewModels.BOTA
             }
         }
 
-        private bool IsExistBookmark(System.Windows.Controls.ListView listView)
+        private bool IsExistBookmark(System.Windows.Controls.ListBox listView)
         {
             bool isExistBookmark = false;
             int index = PDFViewer.CurrentIndex;
@@ -490,13 +490,13 @@ namespace PDF_Master.ViewModels.BOTA
                 {
                     listView.ScrollIntoView(list[0]);
                     //ListBoxItem myListBoxItem = await Task.Run(() => GetListViewItem(listView, list[0]));
-                    ListViewItem myListBoxItem = (ListViewItem)(listView.ItemContainerGenerator.ContainerFromItem(list[0]));
+                    ListBoxItem myListBoxItem = (ListBoxItem)(listView.ItemContainerGenerator.ContainerFromItem(list[0]));
 
-                    List<ListViewItem> listItems = new List<ListViewItem>();
+                    List<ListBoxItem> listItems = new List<ListBoxItem>();
                     foreach (var item in listView.SelectedItems)
                     {
                         listView.ScrollIntoView(item);
-                        ListViewItem listViewItem = (ListViewItem)(listView.ItemContainerGenerator.ContainerFromItem(item));
+                        ListBoxItem listViewItem = (ListBoxItem)(listView.ItemContainerGenerator.ContainerFromItem(item));
                         if (listItems.IndexOf(listViewItem) == -1)
                         {
                             listItems.Add(listViewItem);

+ 22 - 20
PDF Office/Views/BOTA/BookmarkContent.xaml

@@ -89,14 +89,6 @@
                     </Grid>
                 </StackPanel>
             </DataTemplate>
-            <ContextMenu
-                x:Key="ContextMenuBook"
-                FontSize="14"
-                Loaded="ContextMenu_Loaded">
-                <MenuItem Click="MenuItemRename_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Rename}" />
-                <MenuItem Click="MenuChangeItem_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Change}" />
-                <MenuItem Click="MenuItemDeleteCommand_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Delete}" />
-            </ContextMenu>
         </ResourceDictionary>
     </UserControl.Resources>
     <Grid MinHeight="500" Background="{StaticResource color.sys.layout.mg}">
@@ -135,7 +127,13 @@
             </Grid>
         </Border>
         <Grid Grid.Row="1">
-            <ListView
+            <!--
+            VirtualizingPanel.CacheLength="1"
+            VirtualizingPanel.CacheLengthUnit="Page"
+            VirtualizingPanel.IsVirtualizing="True"
+            VirtualizingPanel.ScrollUnit="Pixel"
+            -->
+            <ListBox
                 Name="BookMarkListView"
                 HorizontalContentAlignment="Stretch"
                 Background="{StaticResource color.sys.layout.mg}"
@@ -145,24 +143,28 @@
                 PreviewMouseDown="BookMarkListView_PreviewMouseDown"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 SelectionChanged="BookMarkListView_SelectionChanged"
-                VirtualizingPanel.CacheLength="1"
-                VirtualizingPanel.CacheLengthUnit="Page"
-                VirtualizingPanel.IsVirtualizing="True"
-                VirtualizingPanel.ScrollUnit="Pixel">
-                <ListView.ItemsPanel>
+                SelectionMode="Extended">
+                <ListBox.ContextMenu>
+                    <ContextMenu x:Name="ContextMenuBook" FontSize="14" Visibility="Collapsed">
+                        <MenuItem Click="MenuItemRename_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Rename}" />
+                        <MenuItem Click="MenuChangeItem_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Change}" />
+                        <MenuItem Click="MenuItemDeleteCommand_Click" Header="{x:Static mainPageLoader:MainPage.Bookmark_Delete}" />
+                    </ContextMenu>
+                </ListBox.ContextMenu>
+                <ListBox.ItemsPanel>
                     <ItemsPanelTemplate>
                         <VirtualizingStackPanel Margin="-5,0,0,0" Background="Transparent" />
                     </ItemsPanelTemplate>
-                </ListView.ItemsPanel>
+                </ListBox.ItemsPanel>
 
-                <ListView.ItemContainerStyle>
-                    <Style BasedOn="{StaticResource ListViewItemGraySelectStyle}" TargetType="ListViewItem">
+                <ListBox.ItemContainerStyle>
+                    <Style BasedOn="{StaticResource ListBoxItemGraySelectStyle}" TargetType="ListBoxItem">
                         <EventSetter Event="PreviewMouseDown" Handler="ListViewItem_MouseButtonDown" />
                         <EventSetter Event="LostFocus" Handler="ListViewItem_LostFocus" />
-                        <Setter Property="ContextMenu" Value="{StaticResource ContextMenuBook}" />
+                        <!--<Setter Property="ContextMenu" Value="{StaticResource ContextMenuBook}" />-->
                     </Style>
-                </ListView.ItemContainerStyle>
-            </ListView>
+                </ListBox.ItemContainerStyle>
+            </ListBox>
         </Grid>
         <StackPanel
             Name="EmptyPanel"

+ 50 - 39
PDF Office/Views/BOTA/BookmarkContent.xaml.cs

@@ -57,7 +57,7 @@ namespace PDF_Master.Views.BOTA
             BookMarkListView.SelectedIndex = -1;
             foreach (var item in BookMarkListView.Items)
             {
-                ListViewItem listItem = (ListViewItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(item));
+                ListBoxItem listItem = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(item));
                 if (listItem != null)
                 {
                     TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(listItem);
@@ -81,7 +81,7 @@ namespace PDF_Master.Views.BOTA
         {
             object[] objects = new object[] { sender, e };
             TextBlock textBlock = null;
-            ListViewItem listBoxItem = (sender as ListViewItem);
+            ListBoxItem listBoxItem = (sender as ListBoxItem);
             if (e.LeftButton == MouseButtonState.Pressed)
             {
                 if (e.ClickCount >= 2)
@@ -115,48 +115,59 @@ namespace PDF_Master.Views.BOTA
                     viewModel.ListViewItemMouseDownCommand.Execute(sender);
                 }
             }
-            //else if (e.RightButton == MouseButtonState.Pressed)
-            //{
-            //    ContextMenu contextMenu = listBoxItem.ContextMenu;
-            //    if (contextMenu.Items.Count == 3)
-            //    {
-            //        MenuItem rename = contextMenu.Items[0] as MenuItem;
-            //        MenuItem editPageIndex = contextMenu.Items[1] as MenuItem;
-            //        MenuItem del = contextMenu.Items[2] as MenuItem;
-            //        if (isSelects)
-            //        {
-            //            rename.IsEnabled = false;
-            //            editPageIndex.IsEnabled = false;
-            //            //isSelects = false;
-            //        }
-            //        else
-            //        {
-            //            CPDFBookmark bookmark = (CPDFBookmark)listBoxItem.DataContext;
-            //            if (viewModel.PDFViewer.CurrentIndex == bookmark.PageIndex)
-            //            {
-            //                editPageIndex.IsEnabled = false;
-            //                return;
-            //            }
-            //            rename.IsEnabled = true;
-            //            editPageIndex.IsEnabled = true;
-            //            editPageIndex.CommandParameter = listBoxItem.DataContext;
-            //            editPageIndex.Command = viewModel.EditPageIndexCommand;
-            //        }
-            //    }
-            //}
+            else if (e.RightButton == MouseButtonState.Pressed)
+            {
+                if (histotyListBoxItem != listBoxItem)
+                {
+                    if (histotyListBoxItem != null)
+                    {
+                        histotyListBoxItem.IsSelected = false;
+                        textBlock = CommonHelper.FindVisualChild<TextBlock>(histotyListBoxItem);
+                        textBlock.Visibility = Visibility.Visible;
+                        textBlock.Focusable = true;
+                    }
+                }
+            }
         }
 
         private bool isSelects = false;
 
         private void BookMarkListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-            var a1 = (sender as ListView).SelectedItems.Count;
-            if (a1 > 1)
+            MenuItem rename = ContextMenuBook.Items[0] as MenuItem;
+            MenuItem editPageIndex = ContextMenuBook.Items[1] as MenuItem;
+            MenuItem del = ContextMenuBook.Items[2] as MenuItem;
+            var a1 = (sender as ListBox).SelectedItems.Count;
+            if (a1 >= 1)
             {
                 isSelects = true;
+                ContextMenuBook.Visibility = Visibility.Visible;
+
+                if (a1 > 1)
+                {
+                    rename.IsEnabled = false;
+                    editPageIndex.IsEnabled = false;
+                }
+                if (a1 == 1)
+                {
+                    isSelects = false;
+                    CPDFBookmark bookmark = null;
+                    if (BookMarkListView.SelectedItem != null)
+                    {
+                        bookmark = (CPDFBookmark)BookMarkListView.SelectedItem;
+                        if (viewModel.PDFViewer.CurrentIndex == bookmark.PageIndex)
+                        {
+                            editPageIndex.IsEnabled = false;
+                            return;
+                        }
+                        rename.IsEnabled = true;
+                        editPageIndex.IsEnabled = true;
+                    }
+                }
             }
             else
             {
+                ContextMenuBook.Visibility = Visibility.Collapsed;
                 isSelects = false;
             }
         }
@@ -192,7 +203,7 @@ namespace PDF_Master.Views.BOTA
         /// <param name="e"></param>
         private void ListViewItem_LostFocus(object sender, RoutedEventArgs e)
         {
-            ListViewItem listItem = sender as ListViewItem;
+            ListBoxItem listItem = sender as ListBoxItem;
             if (listItem != null)
             {
                 BookMarkListView.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged;
@@ -272,7 +283,7 @@ namespace PDF_Master.Views.BOTA
                 {
                     BookMarkListView.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged;
                     isRename = true;
-                    ListViewItem listBoxItem = (ListViewItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(bookmark));
+                    ListBoxItem listBoxItem = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(bookmark));
                     histotyListBoxItem = listBoxItem;
 
                     TextBox textBox = CommonHelper.FindVisualChild<TextBox>(listBoxItem);
@@ -297,12 +308,12 @@ namespace PDF_Master.Views.BOTA
                 if (result != null)
                 {
                     //获取当前鼠标指针下的容器
-                    var listBoxItem = CommonHelper.FindVisualParent<ListViewItem>(result.VisualHit);
+                    var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
                     if (listBoxItem == null)
                     {
                         if (BookMarkListView.SelectedItem != null)
                         {
-                            ListViewItem item = (ListViewItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(BookMarkListView.SelectedItem));
+                            ListBoxItem item = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(BookMarkListView.SelectedItem));
                             item.IsSelected = false;
                             TextBlock box = CommonHelper.FindVisualChild<TextBlock>(item);
                             box.Visibility = Visibility.Visible;
@@ -366,7 +377,7 @@ namespace PDF_Master.Views.BOTA
             if (viewModel.IsHasBookmark == false)
             {
                 BookMarkListView.ScrollIntoView(viewModel.AddCPDFBookmark);
-                ListViewItem myListBoxItem = (ListViewItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(viewModel.AddCPDFBookmark));
+                ListBoxItem myListBoxItem = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(viewModel.AddCPDFBookmark));
                 if (myListBoxItem == null)
                 {
                     BookMarkListView.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged;
@@ -388,7 +399,7 @@ namespace PDF_Master.Views.BOTA
             if (itemContainer.Status == GeneratorStatus.ContainersGenerated)
             {
                 BookMarkListView.ScrollIntoView(viewModel.AddCPDFBookmark);
-                ListViewItem myListBoxItem = (ListViewItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(viewModel.AddCPDFBookmark));
+                ListBoxItem myListBoxItem = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(viewModel.AddCPDFBookmark));
                 if (myListBoxItem != null)
                 {
                     if (myListBoxItem.RenderSize.Width < 0 && myListBoxItem.RenderSize.Height < 0)