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
{
///
/// BookmarkContent.xaml 的交互逻辑
///
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(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(histotyListBoxItem);
// textBlock.Visibility = Visibility.Visible;
// textBlock.Focusable = true;
//}
if (histotyListBoxItem != listBoxItem)
{
if (histotyListBoxItem != null)
{
histotyListBoxItem.IsSelected = false;
textBlock = CommonHelper.FindVisualChild(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(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(result.VisualHit);
if (listBoxItem == null)
{
if (BookMarkListView.SelectedItem != null)
{
ListBoxItem item = (ListBoxItem)(BookMarkListView.ItemContainerGenerator.ContainerFromItem(BookMarkListView.SelectedItem));
item.IsSelected = false;
TextBlock box = CommonHelper.FindVisualChild(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(histotyListBoxItem);
textBlock.Visibility = Visibility.Visible;
textBlock.Focusable = true;
}
}
}
else
{
listBoxItem.Focus();
}
}
BookMarkListView.Focus();
}
}
}