init
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using DTS.Common.Interface.Groups.GroupTemplateList;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using DTS.Common.Controls;
|
||||
using DTS.Common.Interface.Groups.GroupList;
|
||||
using DTS.Common.Utils;
|
||||
|
||||
// ReSharper disable CheckNamespace
|
||||
|
||||
namespace GroupList
|
||||
{
|
||||
/// <inheritdoc cref="IGroupListView" />
|
||||
/// <summary>
|
||||
/// Interaction logic for GroupListView.xaml
|
||||
/// </summary>
|
||||
public partial class GroupListView : IGroupListView
|
||||
{
|
||||
public GroupListView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ListViewHeader_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var colHeader = (GridViewColumnHeader)e.OriginalSource;
|
||||
var viewModel = (IGroupListViewModel)colHeader.DataContext;
|
||||
viewModel.Sort(colHeader.Tag, true);
|
||||
}
|
||||
private void GridViewColumnHeaderSearchable_OnSearch(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var searchTerm = (string)e.OriginalSource;
|
||||
var columnTag = (sender as GridViewColumnHeaderSearchable)?.Tag;
|
||||
var vm = (IGroupListViewModel)DataContext;
|
||||
vm.Filter(columnTag, searchTerm);
|
||||
}
|
||||
private void GridViewColumnHeader_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var vm = (IGroupListViewModel)DataContext;
|
||||
var columnTag = (sender as GridViewColumnHeaderSearchable)?.Tag ?? Utils.FindChild<GridViewColumnHeaderSearchable>((DependencyObject)e.OriginalSource, null)?.Tag;
|
||||
vm?.Sort(columnTag, true);
|
||||
}
|
||||
private void MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (!(sender is ListView lv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var index = GetCurrentIndex(e.GetPosition, lv);
|
||||
if (index >= 0 && index < lv.Items.Count)
|
||||
{
|
||||
var vm = (IGroupListViewModel)lv.DataContext;
|
||||
vm.MouseDoubleClick(index);
|
||||
}
|
||||
}
|
||||
|
||||
private delegate Point GetPositionDelegate(IInputElement element);
|
||||
private static int GetCurrentIndex(GetPositionDelegate getPosition, ListView lv)
|
||||
{
|
||||
var index = -1;
|
||||
for (var i = 0; i < lv.Items.Count; i++)
|
||||
{
|
||||
var item = GetListViewItem(i, lv);
|
||||
if (item == null)
|
||||
continue;
|
||||
if (IsMouseOverTarget(item, getPosition))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
private static ListViewItem GetListViewItem(int index, ListView lv)
|
||||
{
|
||||
return lv.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem;
|
||||
}
|
||||
private static bool IsMouseOverTarget(Visual target, GetPositionDelegate getPosition)
|
||||
{
|
||||
var bounds = VisualTreeHelper.GetDescendantBounds(target);
|
||||
var mousePos = getPosition((IInputElement)target);
|
||||
return bounds.Contains(mousePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user