Selecting first mail when thread is expanded.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using CommunityToolkit.Mvvm.Messaging;
|
using CommunityToolkit.Mvvm.Messaging;
|
||||||
using MoreLinq;
|
using MoreLinq;
|
||||||
@@ -47,6 +48,13 @@ namespace Wino.Controls.Advanced
|
|||||||
set { SetValue(LoadMoreCommandProperty, value); }
|
set { SetValue(LoadMoreCommandProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsThreadScrollingEnabled
|
||||||
|
{
|
||||||
|
get { return (bool)GetValue(IsThreadScrollingEnabledProperty); }
|
||||||
|
set { SetValue(IsThreadScrollingEnabledProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsThreadScrollingEnabledProperty = DependencyProperty.Register(nameof(IsThreadScrollingEnabled), typeof(bool), typeof(WinoListView), new PropertyMetadata(false));
|
||||||
public static readonly DependencyProperty LoadMoreCommandProperty = DependencyProperty.Register(nameof(LoadMoreCommand), typeof(ICommand), typeof(WinoListView), new PropertyMetadata(null));
|
public static readonly DependencyProperty LoadMoreCommandProperty = DependencyProperty.Register(nameof(LoadMoreCommand), typeof(ICommand), typeof(WinoListView), new PropertyMetadata(null));
|
||||||
public static readonly DependencyProperty IsThreadListViewProperty = DependencyProperty.Register(nameof(IsThreadListView), typeof(bool), typeof(WinoListView), new PropertyMetadata(false, new PropertyChangedCallback(OnIsThreadViewChanged)));
|
public static readonly DependencyProperty IsThreadListViewProperty = DependencyProperty.Register(nameof(IsThreadListView), typeof(bool), typeof(WinoListView), new PropertyMetadata(false, new PropertyChangedCallback(OnIsThreadViewChanged)));
|
||||||
public static readonly DependencyProperty ItemDeletedCommandProperty = DependencyProperty.Register(nameof(ItemDeletedCommand), typeof(ICommand), typeof(WinoListView), new PropertyMetadata(null));
|
public static readonly DependencyProperty ItemDeletedCommandProperty = DependencyProperty.Register(nameof(ItemDeletedCommand), typeof(ICommand), typeof(WinoListView), new PropertyMetadata(null));
|
||||||
@@ -316,10 +324,19 @@ namespace Wino.Controls.Advanced
|
|||||||
}
|
}
|
||||||
else if (addedItem is ThreadMailItemViewModel threadMailItemViewModel)
|
else if (addedItem is ThreadMailItemViewModel threadMailItemViewModel)
|
||||||
{
|
{
|
||||||
// threadMailItemViewModel.IsThreadExpanded = true;
|
if (IsThreadScrollingEnabled)
|
||||||
|
{
|
||||||
|
if (internalScrollviewer != null && ContainerFromItem(threadMailItemViewModel) is FrameworkElement threadFrameworkElement)
|
||||||
|
{
|
||||||
|
internalScrollviewer.ScrollToElement(threadFrameworkElement, true, true, bringToTopOrLeft: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't select thread containers.
|
// Try to select first item.
|
||||||
// SelectedItems.Remove(addedItem);
|
if (GetThreadInternalListView(threadMailItemViewModel) is WinoListView internalListView)
|
||||||
|
{
|
||||||
|
internalListView.SelectFirstItem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,6 +372,27 @@ namespace Wino.Controls.Advanced
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void SelectFirstItem()
|
||||||
|
{
|
||||||
|
if (Items.Count > 0)
|
||||||
|
{
|
||||||
|
if (Items[0] is MailItemViewModel firstMailItemViewModel)
|
||||||
|
{
|
||||||
|
// Make sure the invisible container is realized.
|
||||||
|
await Task.Delay(250);
|
||||||
|
|
||||||
|
if (ContainerFromItem(firstMailItemViewModel) is ListViewItem firstItemContainer)
|
||||||
|
{
|
||||||
|
firstItemContainer.IsSelected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
firstMailItemViewModel.IsSelected = true;
|
||||||
|
|
||||||
|
// WeakReferenceMessenger.Default.Send(new MailItemSelectedEvent(firstMailItemViewModel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private WinoListView GetThreadInternalListView(ThreadMailItemViewModel threadMailItemViewModel)
|
private WinoListView GetThreadInternalListView(ThreadMailItemViewModel threadMailItemViewModel)
|
||||||
{
|
{
|
||||||
var itemContainer = ContainerFromItem(threadMailItemViewModel);
|
var itemContainer = ContainerFromItem(threadMailItemViewModel);
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ namespace Wino.Extensions
|
|||||||
|
|
||||||
if (isVerticalScrolling)
|
if (isVerticalScrolling)
|
||||||
{
|
{
|
||||||
scrollViewer.ChangeView(null, position.Y, zoomFactor, !smoothScrolling);
|
// Accomodate for additional header.
|
||||||
|
scrollViewer.ChangeView(null, Math.Max(0, position.Y - 48), zoomFactor, !smoothScrolling);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user