123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using PDF_Office.Helper;
- using PDF_Office.ViewModels.BOTA;
- 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.BOTA
- {
- /// <summary>
- /// BookmarkContent.xaml 的交互逻辑
- /// </summary>
- public partial class BookmarkContent : UserControl
- {
- private BookmarkContentViewModel viewModel = null;
- private ListBoxItem histotyListBoxItem = null;
- public BookmarkContent()
- {
- InitializeComponent();
- viewModel = this.DataContext as BookmarkContentViewModel;
- }
- private void TxtTitleInput_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (sender is TextBox && IsLoaded)
- {
- TextBox textBox = sender as TextBox;
- if (textBox.Visibility == Visibility.Visible)
- {
- textBox.Focus();
- }
- }
- }
- private void ListViewItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- object[] objects = new object[] { sender, e };
- TextBlock textBlock = null;
- ListBoxItem listBoxItem = (sender as ListBoxItem);
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- if (e.ClickCount >= 2)
- {
- histotyListBoxItem = listBoxItem;
- if (e.OriginalSource is TextBlock)
- {
- textBlock = (TextBlock)e.OriginalSource;
- if (textBlock != null)
- {
- listBoxItem.IsSelected = true;
- listBoxItem.IsSelected = true;
- listBoxItem.Focus();
- textBlock.Visibility = Visibility.Collapsed;
- TextBox textBox = CommonHelper.FindVisualChild<TextBox>(listBoxItem);
- textBox.Dispatcher.BeginInvoke(new Action(() =>
- {
- textBox.Focus();
- textBox.SelectAll();
- }));
- //textBox.PreviewMouseDown += new MouseButtonEventHandler(TxtTitleInput_PreviewMouseLeftButtonDown);
- //TxtTitleInput_PreviewMouseLeftButtonDown(textBox, mouse);
- }
- }
- }
- else if (e.ClickCount == 1)
- {
- //var pos = e.GetPosition(histotyListBoxItem);
- //var result = VisualTreeHelper.HitTest(BookMarkListView, pos);
- //if (result == null)
- //{
- // histotyListBoxItem.IsSelected = false;
- // textBlock = CommonHelper.FindVisualChild<TextBlock>(histotyListBoxItem);
- // textBlock.Visibility = Visibility.Visible;
- // textBlock.Focusable = true;
- //}
- if (histotyListBoxItem != listBoxItem)
- {
- if (histotyListBoxItem != null)
- {
- histotyListBoxItem.IsSelected = false;
- textBlock = CommonHelper.FindVisualChild<TextBlock>(histotyListBoxItem);
- textBlock.Visibility = Visibility.Visible;
- textBlock.Focusable = true;
- }
- }
- viewModel.ListViewItemMouseDownCommand.Execute(sender);
- }
- }
- else if (e.RightButton == MouseButtonState.Pressed)
- {
- listBoxItem.IsSelected = true;
- listBoxItem.Focus();
- }
- }
- private void ListViewItem_LostFocus(object sender, RoutedEventArgs e)
- {
- ListBoxItem listItem = sender as ListBoxItem;
- if (listItem != null)
- {
- viewModel.LostFocusCommand.Execute(listItem);
- TextBlock textBox = CommonHelper.FindVisualChild<TextBlock>(listItem);
- if (textBox.Visibility == Visibility.Collapsed)
- {
- listItem.IsSelected = true;
- }
- else
- {
- listItem.IsSelected = false;
- }
- }
- }
- private void BookMarkListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var pos = e.GetPosition(BookMarkListView);
- var result = VisualTreeHelper.HitTest(BookMarkListView, pos);
- if (result != null)
- {
- //获取当前鼠标指针下的容器
- var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
- if (listBoxItem == null)
- {
- if (BookMarkListView.SelectedItem != null)
- {
- ListBoxItem item = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(BookMarkListView.SelectedItem));
- item.IsSelected = false;
- TextBlock box = CommonHelper.FindVisualChild<TextBlock>(item);
- box.Visibility = Visibility.Visible;
- BookMarkListView.SelectedItems.Clear();
- }
- if (histotyListBoxItem != null)
- {
- var pos1 = e.GetPosition(histotyListBoxItem);
- var result1 = VisualTreeHelper.HitTest(BookMarkListView, pos1);
- if (result1 == null)
- {
- histotyListBoxItem.IsSelected = false;
- TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(histotyListBoxItem);
- textBlock.Visibility = Visibility.Visible;
- textBlock.Focusable = true;
- }
- }
- }
- else
- {
- listBoxItem.Focus();
- }
- }
- BookMarkListView.Focus();
- }
- }
- }
|