New list view items.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Linq;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
|
||||
@@ -6,10 +7,20 @@ namespace Wino.Mail.WinUI.Controls.ListView;
|
||||
|
||||
public partial class WinoListView : Microsoft.UI.Xaml.Controls.ListView
|
||||
{
|
||||
public bool IsThreadListView
|
||||
{
|
||||
get { return (bool)GetValue(IsThreadListViewProperty); }
|
||||
set { SetValue(IsThreadListViewProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsThreadListViewProperty = DependencyProperty.Register(nameof(IsThreadListView), typeof(bool), typeof(WinoListView), new PropertyMetadata(false));
|
||||
|
||||
public bool IsAllSelected => Items.Count == SelectedItems.Count;
|
||||
|
||||
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
|
||||
{
|
||||
base.PrepareContainerForItemOverride(element, item);
|
||||
|
||||
if (item is MailItemViewModel mailItemViewModel && element is WinoMailItemViewModelListViewItem container)
|
||||
{
|
||||
// Ensure the container's selection state matches the model's state
|
||||
@@ -19,18 +30,52 @@ public partial class WinoListView : Microsoft.UI.Xaml.Controls.ListView
|
||||
}
|
||||
else if (item is ThreadMailItemViewModel threadMailItemViewModel && element is WinoThreadMailItemViewModelListViewItem threadContainer)
|
||||
{
|
||||
threadContainer.IsSelected = threadMailItemViewModel.IsSelected;
|
||||
threadContainer.IsThreadExpanded = threadMailItemViewModel.IsThreadExpanded;
|
||||
}
|
||||
|
||||
base.PrepareContainerForItemOverride(element, item);
|
||||
}
|
||||
|
||||
protected override void ClearContainerForItemOverride(DependencyObject element, object item)
|
||||
public WinoMailItemViewModelListViewItem? GetMailItemContainer(MailItemViewModel mailItemViewModel)
|
||||
{
|
||||
if (element is WinoThreadMailItemViewModelListViewItem threadMailItemViewModelListViewItem) threadMailItemViewModelListViewItem.Cleanup();
|
||||
if (element is WinoMailItemViewModelListViewItem winoMailItemViewModelListViewItem) winoMailItemViewModelListViewItem.Cleanup();
|
||||
foreach (var item in Items)
|
||||
{
|
||||
if (item is MailItemViewModel mailItem && mailItem.Id == mailItemViewModel.Id) return ContainerFromItem(mailItemViewModel) as WinoMailItemViewModelListViewItem;
|
||||
if (item is ThreadMailItemViewModel threadMailItem && threadMailItem.GetContainingIds().Contains(mailItemViewModel.MailCopy.UniqueId))
|
||||
{
|
||||
var threadContainer = ContainerFromItem(threadMailItem) as WinoThreadMailItemViewModelListViewItem;
|
||||
|
||||
base.ClearContainerForItemOverride(element, item);
|
||||
// Try to get the inner WinoListView.
|
||||
if (threadContainer != null)
|
||||
{
|
||||
var innerListViewControl = threadContainer.GetWinoListViewControl();
|
||||
|
||||
return innerListViewControl?.ContainerFromItem(mailItemViewModel) as WinoMailItemViewModelListViewItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public WinoThreadMailItemViewModelListViewItem? GetThreadMailItemContainer(ThreadMailItemViewModel threadMailItemViewModel)
|
||||
=> ContainerFromItem(threadMailItemViewModel) as WinoThreadMailItemViewModelListViewItem;
|
||||
|
||||
public void ToggleItemContainer(IMailListItem mailListItem)
|
||||
{
|
||||
DispatcherQueue.TryEnqueue(() =>
|
||||
{
|
||||
if (mailListItem is MailItemViewModel mailItemViewModel)
|
||||
{
|
||||
var container = GetMailItemContainer(mailItemViewModel);
|
||||
container?.IsSelected = mailItemViewModel.IsSelected;
|
||||
}
|
||||
else if (mailListItem is ThreadMailItemViewModel threadMailItemViewModel)
|
||||
{
|
||||
var container = GetThreadMailItemContainer(threadMailItemViewModel);
|
||||
container?.IsSelected = threadMailItemViewModel.IsSelected;
|
||||
container?.IsThreadExpanded = threadMailItemViewModel.IsThreadExpanded;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public bool SelectMailItemContainer(MailItemViewModel mailItemViewModel)
|
||||
|
||||
@@ -11,37 +11,76 @@
|
||||
|
||||
<ResourceDictionary>
|
||||
<!-- Thread Mail ListViewItem Style -->
|
||||
<Style x:Key="DefaultThreadListViewItemStyle" TargetType="local:WinoMailItemViewModelListViewItem">
|
||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
||||
<Setter Property="Background" Value="{ThemeResource ListViewItemBackground}" />
|
||||
<Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}" />
|
||||
<Setter Property="TabNavigation" Value="Local" />
|
||||
<Setter Property="IsHoldingEnabled" Value="True" />
|
||||
<Setter Property="Padding" Value="16,0,12,0" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" />
|
||||
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}" />
|
||||
<Setter Property="AllowDrop" Value="False" />
|
||||
<Setter Property="UseSystemFocusVisuals" Value="True" />
|
||||
<Setter Property="FocusVisualMargin" Value="1" />
|
||||
<Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}" />
|
||||
<Setter Property="FocusVisualPrimaryThickness" Value="2" />
|
||||
<Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}" />
|
||||
<Setter Property="FocusVisualSecondaryThickness" Value="1" />
|
||||
<Style
|
||||
x:Key="DefaultThreadListViewItemStyle"
|
||||
BasedOn="{StaticResource DefaultListViewItemStyle}"
|
||||
TargetType="local:WinoThreadMailItemViewModelListViewItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:WinoMailItemViewModelListViewItem">
|
||||
<!-- Expandable Content -->
|
||||
<ContentPresenter
|
||||
x:Name="ThreadContent"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
<ControlTemplate TargetType="local:WinoThreadMailItemViewModelListViewItem">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="8" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid
|
||||
x:Name="RootGrid"
|
||||
Grid.ColumnSpan="2"
|
||||
Background="{ThemeResource ListViewItemBackground}"
|
||||
CornerRadius="{ThemeResource ControlCornerRadius}" />
|
||||
<Border
|
||||
x:Name="SelectionIndicator"
|
||||
Width="4"
|
||||
Margin="0,16"
|
||||
HorizontalAlignment="Center"
|
||||
Background="{ThemeResource ListViewItemSelectionIndicatorBrush}"
|
||||
CornerRadius="4"
|
||||
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item.IsSelected, Mode=OneWay}" />
|
||||
<!-- Expandable Content -->
|
||||
<ContentPresenter
|
||||
x:Name="ThreadContent"
|
||||
Grid.Column="1"
|
||||
Margin="6,0,0,0"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal" />
|
||||
<VisualState x:Name="PointerOver">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundPointerOver}" />
|
||||
<Setter Target="ThreadContent.Foreground" Value="{ThemeResource ListViewItemForegroundPointerOver}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Selected">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelected}" />
|
||||
<Setter Target="ThreadContent.Foreground" Value="{ThemeResource ListViewItemForegroundSelected}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPointerOver">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelectedPointerOver}" />
|
||||
<Setter Target="ThreadContent.Foreground" Value="{ThemeResource ListViewItemForegroundSelected}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Pressed">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundPressed}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="PressedSelected">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelectedPressed}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
@@ -52,7 +91,76 @@
|
||||
<Style
|
||||
x:Key="DefaultMailListViewItemStyle"
|
||||
BasedOn="{StaticResource DefaultListViewItemStyle}"
|
||||
TargetType="local:WinoMailItemViewModelListViewItem" />
|
||||
TargetType="local:WinoMailItemViewModelListViewItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:WinoMailItemViewModelListViewItem">
|
||||
<Grid
|
||||
x:Name="RootGrid"
|
||||
Margin="0,2"
|
||||
Background="{ThemeResource ListViewItemBackground}"
|
||||
CornerRadius="{ThemeResource ControlCornerRadius}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="8" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
x:Name="SelectionIndicator"
|
||||
Width="4"
|
||||
Margin="0,16"
|
||||
HorizontalAlignment="Center"
|
||||
Background="{ThemeResource ListViewItemSelectionIndicatorBrush}"
|
||||
CornerRadius="4"
|
||||
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Item.IsSelected, Mode=OneWay}" />
|
||||
|
||||
<ContentPresenter
|
||||
x:Name="MailContent"
|
||||
Grid.Column="1"
|
||||
Margin="6,0,0,0"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Background="Transparent"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualState x:Name="Normal" />
|
||||
<VisualState x:Name="PointerOver">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundPointerOver}" />
|
||||
<Setter Target="MailContent.Foreground" Value="{ThemeResource ListViewItemForegroundPointerOver}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Selected">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelected}" />
|
||||
<Setter Target="MailContent.Foreground" Value="{ThemeResource ListViewItemForegroundSelected}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="SelectedPointerOver">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelectedPointerOver}" />
|
||||
<Setter Target="MailContent.Foreground" Value="{ThemeResource ListViewItemForegroundSelected}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Pressed">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundPressed}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="PressedSelected">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="RootGrid.Background" Value="{ThemeResource ListViewItemBackgroundSelectedPressed}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<local:WinoMailItemContainerStyleSelector
|
||||
x:Name="WinoMailItemContainerStyleSelector"
|
||||
|
||||
@@ -12,7 +12,8 @@ public partial class WinoMailItemContainerStyleSelector : StyleSelector
|
||||
protected override Style SelectStyleCore(object item, DependencyObject container)
|
||||
{
|
||||
if (item is MailItemViewModel) return MailItemStyle ?? throw new Exception($"Missing style for {nameof(MailItemViewModel)}");
|
||||
if (item is ThreadMailItemViewModel) return ThreadStyle ?? throw new Exception($"Missing style for {nameof(ThreadMailItemViewModel)}");
|
||||
if (item is ThreadMailItemViewModel)
|
||||
return ThreadStyle ?? throw new Exception($"Missing style for {nameof(ThreadMailItemViewModel)}");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,86 +1,23 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.UI.Xaml;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messaging.Client.Mails;
|
||||
|
||||
namespace Wino.Mail.WinUI.Controls.ListView;
|
||||
|
||||
public partial class WinoMailItemViewModelListViewItem : ListViewItem
|
||||
{
|
||||
private readonly long _selectionChangeCallbackToken;
|
||||
[GeneratedDependencyProperty]
|
||||
public partial MailItemViewModel? Item { get; set; }
|
||||
|
||||
public WinoMailItemViewModelListViewItem()
|
||||
{
|
||||
DefaultStyleKey = typeof(WinoMailItemViewModelListViewItem);
|
||||
|
||||
_selectionChangeCallbackToken = RegisterPropertyChangedCallback(IsSelectedProperty, OnIsSelectedChanged);
|
||||
}
|
||||
|
||||
protected override void OnContentChanged(object oldContent, object newContent)
|
||||
{
|
||||
base.OnContentChanged(oldContent, newContent);
|
||||
|
||||
if (oldContent is MailItemViewModel oldMailItem)
|
||||
{
|
||||
UnregisterSelectionCallback(oldMailItem);
|
||||
}
|
||||
|
||||
if (newContent is MailItemViewModel newMailItem)
|
||||
{
|
||||
IsSelected = newMailItem.IsSelected;
|
||||
RegisterSelectionCallback(newMailItem);
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
if (Content is MailItemViewModel mailItem)
|
||||
{
|
||||
UnregisterSelectionCallback(mailItem);
|
||||
|
||||
UnregisterPropertyChangedCallback(IsSelectedProperty, _selectionChangeCallbackToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnregisterSelectionCallback(IMailListItem mailItem)
|
||||
{
|
||||
mailItem.PropertyChanged -= MailPropChanged;
|
||||
}
|
||||
|
||||
private void RegisterSelectionCallback(IMailListItem mailItem)
|
||||
{
|
||||
mailItem.PropertyChanged -= MailPropChanged;
|
||||
mailItem.PropertyChanged += MailPropChanged;
|
||||
}
|
||||
|
||||
// From model
|
||||
private void MailPropChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (sender is not MailItemViewModel mailItem) return;
|
||||
|
||||
if (e.PropertyName == nameof(MailItemViewModel.IsSelected)) ApplySelectionForContainer(mailItem);
|
||||
}
|
||||
|
||||
// From container.
|
||||
private void OnIsSelectedChanged(DependencyObject sender, DependencyProperty dp)
|
||||
{
|
||||
if (Content is IMailListItem mailItem)
|
||||
{
|
||||
ApplySelectionForModel(mailItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplySelectionForModel(IMailListItem mailItem)
|
||||
{
|
||||
mailItem.IsSelected = IsSelected;
|
||||
WeakReferenceMessenger.Default.Send(new SelectedItemsChangedMessage());
|
||||
}
|
||||
|
||||
private void ApplySelectionForContainer(IMailListItem mailItem)
|
||||
{
|
||||
if (IsSelected != mailItem.IsSelected)
|
||||
{
|
||||
IsSelected = mailItem.IsSelected;
|
||||
}
|
||||
if (newContent is MailItemViewModel mailItemViewModel) Item = mailItemViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Wino.Controls;
|
||||
@@ -10,30 +10,29 @@ namespace Wino.Mail.WinUI.Controls.ListView;
|
||||
|
||||
public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
|
||||
{
|
||||
public bool IsThreadExpanded
|
||||
[GeneratedDependencyProperty]
|
||||
public partial bool IsThreadExpanded { get; set; }
|
||||
|
||||
[GeneratedDependencyProperty]
|
||||
public partial ThreadMailItemViewModel? Item { get; set; }
|
||||
|
||||
protected override void OnContentChanged(object oldContent, object newContent)
|
||||
{
|
||||
get { return (bool)GetValue(IsThreadExpandedProperty); }
|
||||
set { SetValue(IsThreadExpandedProperty, value); }
|
||||
base.OnContentChanged(oldContent, newContent);
|
||||
|
||||
if (newContent is ThreadMailItemViewModel threadMailItemViewModel) Item = threadMailItemViewModel;
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsThreadExpandedProperty = DependencyProperty.Register(nameof(IsThreadExpanded), typeof(bool), typeof(WinoThreadMailItemViewModelListViewItem), new PropertyMetadata(false, new PropertyChangedCallback(OnIsThreadExpandedChanged)));
|
||||
|
||||
private readonly long _selectionChangeCallbackToken;
|
||||
public WinoThreadMailItemViewModelListViewItem()
|
||||
{
|
||||
DefaultStyleKey = typeof(WinoThreadMailItemViewModelListViewItem);
|
||||
|
||||
_selectionChangeCallbackToken = RegisterPropertyChangedCallback(IsSelectedProperty, OnIsSelectedChanged);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
partial void OnIsThreadExpandedChanged(bool newValue)
|
||||
{
|
||||
if (Content is ThreadMailItemViewModel mailItem)
|
||||
{
|
||||
UnregisterSelectionCallback(mailItem);
|
||||
|
||||
UnregisterPropertyChangedCallback(IsSelectedProperty, _selectionChangeCallbackToken);
|
||||
}
|
||||
// 1. Reflect expansion changes to WinoExpander.
|
||||
// 2. Automatically select first item on expansion, if none selected.
|
||||
// 3. Unselect all items on collapse.
|
||||
}
|
||||
|
||||
private static void OnIsThreadExpandedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs dp)
|
||||
@@ -42,79 +41,32 @@ public partial class WinoThreadMailItemViewModelListViewItem : ListViewItem
|
||||
// 2. Automatically select first item on expansion, if none selected.
|
||||
// 3. Unselect all items on collapse.
|
||||
|
||||
var control = sender as WinoThreadMailItemViewModelListViewItem;
|
||||
//var control = sender as WinoThreadMailItemViewModelListViewItem;
|
||||
|
||||
var innerControl = control?.GetWinoListViewControl();
|
||||
var expander = control?.GetExpander();
|
||||
//var innerControl = control?.GetWinoListViewControl();
|
||||
//var expander = control?.GetExpander();
|
||||
|
||||
if (innerControl == null || control == null || expander == null) return;
|
||||
//if (innerControl == null || control == null || expander == null) return;
|
||||
|
||||
|
||||
// 2
|
||||
if (control.IsThreadExpanded && innerControl.SelectedItems.Count == 0 && innerControl.Items.Count > 0)
|
||||
{
|
||||
innerControl.SelectedItems.Clear();
|
||||
//// 2
|
||||
//if (control.IsThreadExpanded && innerControl.SelectedItems.Count == 0 && innerControl.Items.Count > 0)
|
||||
//{
|
||||
// innerControl.SelectedItems.Clear();
|
||||
|
||||
// Make item selected, container might not be realized yet, so set on the model.
|
||||
// It'll appear selected when container is realized.
|
||||
// // Make item selected, container might not be realized yet, so set on the model.
|
||||
// // It'll appear selected when container is realized.
|
||||
|
||||
var firstItem = innerControl.Items.FirstOrDefault() as MailItemViewModel;
|
||||
// var firstItem = innerControl.Items.FirstOrDefault() as MailItemViewModel;
|
||||
|
||||
firstItem?.IsSelected = true;
|
||||
}
|
||||
// firstItem?.IsSelected = true;
|
||||
//}
|
||||
|
||||
// 1
|
||||
expander.IsExpanded = control.IsThreadExpanded;
|
||||
//// 1
|
||||
//expander.IsExpanded = control.IsThreadExpanded;
|
||||
|
||||
// 3
|
||||
if (!control.IsSelected) innerControl?.SelectedItems.Clear();
|
||||
}
|
||||
|
||||
protected override void OnContentChanged(object oldContent, object newContent)
|
||||
{
|
||||
base.OnContentChanged(oldContent, newContent);
|
||||
|
||||
if (oldContent is ThreadMailItemViewModel oldMailItem)
|
||||
{
|
||||
UnregisterSelectionCallback(oldMailItem);
|
||||
}
|
||||
|
||||
if (newContent is ThreadMailItemViewModel newMailItem)
|
||||
{
|
||||
IsSelected = newMailItem.IsSelected;
|
||||
RegisterSelectionCallback(newMailItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnIsSelectedChanged(DependencyObject sender, DependencyProperty dp)
|
||||
{
|
||||
IsThreadExpanded = IsSelected;
|
||||
}
|
||||
|
||||
public void UnregisterSelectionCallback(ThreadMailItemViewModel mailItem)
|
||||
{
|
||||
mailItem.PropertyChanged -= MailPropChanged;
|
||||
}
|
||||
|
||||
private void MailPropChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (sender is not ThreadMailItemViewModel mailItem) return;
|
||||
|
||||
if (e.PropertyName == nameof(ThreadMailItemViewModel.IsThreadExpanded))
|
||||
{
|
||||
ApplySelectionForContainer(mailItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterSelectionCallback(ThreadMailItemViewModel mailItem)
|
||||
{
|
||||
mailItem.PropertyChanged -= MailPropChanged;
|
||||
mailItem.PropertyChanged += MailPropChanged;
|
||||
}
|
||||
|
||||
private void ApplySelectionForContainer(ThreadMailItemViewModel mailItem)
|
||||
{
|
||||
if (IsThreadExpanded != mailItem.IsThreadExpanded) IsThreadExpanded = mailItem.IsThreadExpanded;
|
||||
//// 3
|
||||
//if (!control.IsSelected) innerControl?.SelectedItems.Clear();
|
||||
}
|
||||
|
||||
public WinoListView? GetWinoListViewControl()
|
||||
|
||||
Reference in New Issue
Block a user