Finished wino expander implementation.

This commit is contained in:
Burak Kaan Köse
2024-08-31 03:18:43 +02:00
parent b9a1756f90
commit 6bb09f10d2
9 changed files with 209 additions and 117 deletions

View File

@@ -192,10 +192,12 @@ namespace Wino.Core.MenuItems
item.IsExpanded = false;
item.IsSelected = false;
Remove(item);
try
{
Remove(item);
}
catch (Exception) { }
});
// RemoveRange(itemsToRemove);
}
}
}

View File

@@ -48,7 +48,7 @@ namespace Wino.Controls.Advanced
}
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));
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 WinoListView()
@@ -64,7 +64,6 @@ namespace Wino.Controls.Advanced
DragItemsCompleted += ItemDragCompleted;
DragItemsStarting += ItemDragStarting;
SelectionChanged += SelectedItemsChanged;
ItemClick += MailItemClicked;
ProcessKeyboardAccelerators += ProcessDelKey;
}
@@ -84,6 +83,22 @@ namespace Wino.Controls.Advanced
internalScrollviewer.ViewChanged += InternalScrollVeiwerViewChanged;
}
private static void OnIsThreadViewChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is WinoListView winoListView)
{
winoListView.AdjustThreadViewContainerVisuals();
}
}
private void AdjustThreadViewContainerVisuals()
{
if (IsThreadListView)
{
ItemContainerTransitions.Clear();
}
}
private double lastestRaisedOffset = 0;
private int lastItemSize = 0;
@@ -159,19 +174,6 @@ namespace Wino.Controls.Advanced
}
}
private void MailItemClicked(object sender, ItemClickEventArgs e)
{
if (e.ClickedItem is ThreadMailItemViewModel clickedThread)
{
clickedThread.IsThreadExpanded = !clickedThread.IsThreadExpanded;
if (!clickedThread.IsThreadExpanded)
{
SelectedItems.Clear();
}
}
}
public void ChangeSelectionMode(ListViewSelectionMode selectionMode)
{
SelectionMode = selectionMode;
@@ -293,6 +295,10 @@ namespace Wino.Controls.Advanced
removedMailItemViewModel.IsSelected = false;
WeakReferenceMessenger.Default.Send(new MailItemSelectionRemovedEvent(removedMailItemViewModel));
}
else if (removedItem is ThreadMailItemViewModel removedThreadItemViewModel)
{
removedThreadItemViewModel.IsThreadExpanded = false;
}
}
}
@@ -313,7 +319,7 @@ namespace Wino.Controls.Advanced
// threadMailItemViewModel.IsThreadExpanded = true;
// Don't select thread containers.
SelectedItems.Remove(addedItem);
// SelectedItems.Remove(addedItem);
}
}
}
@@ -341,10 +347,10 @@ namespace Wino.Controls.Advanced
{
// Tell main list view to unselect all his items.
if (SelectedItems[0] is MailItemViewModel selectedMailItemViewModel)
{
WeakReferenceMessenger.Default.Send(new ResetSingleMailItemSelectionEvent(selectedMailItemViewModel));
}
//if (SelectedItems[0] is MailItemViewModel selectedMailItemViewModel)
//{
// WeakReferenceMessenger.Default.Send(new ResetSingleMailItemSelectionEvent(selectedMailItemViewModel));
//}
}
}
}
@@ -369,7 +375,6 @@ namespace Wino.Controls.Advanced
DragItemsCompleted -= ItemDragCompleted;
DragItemsStarting -= ItemDragStarting;
SelectionChanged -= SelectedItemsChanged;
ItemClick -= MailItemClicked;
ProcessKeyboardAccelerators -= ProcessDelKey;
if (internalScrollviewer != null)

View File

@@ -80,8 +80,6 @@ namespace Wino.Controls
control.UpdateInformation();
}
private async void UpdateInformation()
{
if (KnownHostImage == null || InitialsGrid == null || InitialsTextblock == null || (string.IsNullOrEmpty(FromName) && string.IsNullOrEmpty(FromAddress)))

View File

@@ -2,10 +2,12 @@
x:Class="Wino.Controls.MailItemDisplayInformationControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
xmlns:controls="using:Wino.Controls"
xmlns:domain="using:Wino.Core.Domain"
xmlns:enums="using:Wino.Core.Domain.Enums"
xmlns:helpers="using:Wino.Helpers"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
@@ -154,13 +156,29 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<FontIcon
x:Name="ExpanderChevron"
Margin="0,0,2,0"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE76C;"
Visibility="{x:Bind IsThreadExpanderVisible, Mode=OneWay}" />
<local:AnimatedIcon
xmlns:local="using:Microsoft.UI.Xaml.Controls"
x:Name="ExpandCollapseChevron"
Width="14"
Height="14"
Margin="-4,0,2,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
local:AnimatedIcon.State="NormalOff"
AutomationProperties.AccessibilityView="Raw"
Foreground="{ThemeResource ApplicationForegroundThemeBrush}"
RenderTransformOrigin="0.5, 0.5"
Visibility="{x:Bind IsThreadExpanderVisible, Mode=OneWay}">
<animatedvisuals:AnimatedChevronRightDownSmallVisualSource />
<local:AnimatedIcon.FallbackIconSource>
<local:FontIconSource
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE76C;"
IsTextScaleFactorEnabled="False" />
</local:AnimatedIcon.FallbackIconSource>
<local:AnimatedIcon.RenderTransform />
</local:AnimatedIcon>
<TextBlock
x:Name="TitleText"
@@ -296,7 +314,7 @@
<VisualState x:Name="NotExpanded" />
<VisualState x:Name="ExpandedState">
<VisualState.Setters>
<Setter Target="ExpanderChevron.Glyph" Value="&#xE70D;" />
<Setter Target="ExpandCollapseChevron.(controls:AnimatedIcon.State)" Value="NormalOn" />
</VisualState.Setters>
<VisualState.StateTriggers>
<StateTrigger IsActive="{x:Bind IsThreadExpanded, Mode=OneWay}" />

View File

@@ -2,7 +2,6 @@
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Wino.Core.Domain.Entities;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Models.MailItem;
@@ -29,7 +28,7 @@ namespace Wino.Controls
public static readonly DependencyProperty IsHoverActionsEnabledProperty = DependencyProperty.Register(nameof(IsHoverActionsEnabled), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(true));
public static readonly DependencyProperty Prefer24HourTimeFormatProperty = DependencyProperty.Register(nameof(Prefer24HourTimeFormat), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsThreadExpanderVisibleProperty = DependencyProperty.Register(nameof(IsThreadExpanderVisible), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsThreadExpandedProperty = DependencyProperty.Register(nameof(IsThreadExpanded), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false));
public static readonly DependencyProperty IsThreadExpandedProperty = DependencyProperty.Register(nameof(IsThreadExpanded), typeof(bool), typeof(MailItemDisplayInformationControl), new PropertyMetadata(false, new PropertyChangedCallback(OnIsExpandedChanged)));
public bool IsThreadExpanded
{
@@ -85,7 +84,6 @@ namespace Wino.Controls
set { SetValue(RightHoverActionProperty, value); }
}
public WinoExpander ConnectedExpander
{
get { return (WinoExpander)GetValue(ConnectedExpanderProperty); }
@@ -122,8 +120,6 @@ namespace Wino.Controls
set { SetValue(DisplayModeProperty, value); }
}
private bool tappedHandlingFlag = false;
public MailItemDisplayInformationControl()
{
this.InitializeComponent();
@@ -142,6 +138,20 @@ namespace Wino.Controls
RootContainerVisualWrapper.SizeChanged += (s, e) => leftBackgroundVisual.Size = e.NewSize.ToVector2();
}
private static void OnIsExpandedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is MailItemDisplayInformationControl control)
{
control.AdjustRotation();
}
}
private void AdjustRotation()
{
// ExpanderChevronGrid.Rotation = IsThreadExpanded ? 45 : 0;
}
private void ControlPointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (IsHoverActionsEnabled)
@@ -169,29 +179,9 @@ namespace Wino.Controls
if (package == null) return;
tappedHandlingFlag = true;
HoverActionExecutedCommand?.Execute(package);
}
private void ThreadHeaderTapped(object sender, TappedRoutedEventArgs e)
{
// Due to CanDrag=True, outer expander doesn't get the click event and it doesn't expand. We expand here manually.
// Also hover action button clicks will be delegated here after the execution runs.
// We should not expand the thread if the reason we are here is for hover actions.
//if (tappedHandlingFlag)
//{
// tappedHandlingFlag = false;
// e.Handled = true;
// return;
//}
//if (ConnectedExpander == null) return;
//ConnectedExpander.IsExpanded = !ConnectedExpander.IsExpanded;
}
private void FirstActionClicked(object sender, RoutedEventArgs e)
{
ExecuteHoverAction(LeftHoverAction);

View File

@@ -1,5 +1,7 @@
using Windows.UI.Xaml;
using CommunityToolkit.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Markup;
namespace Wino.Controls
@@ -7,15 +9,18 @@ namespace Wino.Controls
[ContentProperty(Name = nameof(Content))]
public class WinoExpander : Control
{
private const string PART_HeaderGrid = "HeaderGrid";
private const string PART_ContentAreaWrapper = "ContentAreaWrapper";
private const string PART_ContentArea = "ContentArea";
private ContentControl HeaderGrid;
private ContentControl ContentArea;
private Grid ContentAreaWrapper;
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(UIElement), typeof(WinoExpander), new PropertyMetadata(null));
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(WinoExpander), new PropertyMetadata(null));
public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(WinoExpander), new PropertyMetadata(false, new PropertyChangedCallback(OnIsExpandedChanged)));
public bool IsExpanded
{
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public static readonly DependencyProperty TemplateSettingsProperty = DependencyProperty.Register(nameof(TemplateSettings), typeof(WinoExpanderTemplateSettings), typeof(WinoExpander), new PropertyMetadata(new WinoExpanderTemplateSettings()));
public UIElement Content
{
@@ -23,12 +28,54 @@ namespace Wino.Controls
set { SetValue(ContentProperty, value); }
}
public WinoExpanderTemplateSettings TemplateSettings
{
get { return (WinoExpanderTemplateSettings)GetValue(TemplateSettingsProperty); }
set { SetValue(TemplateSettingsProperty, value); }
}
public bool IsExpanded
{
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public UIElement Header
{
get { return (UIElement)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
HeaderGrid = GetTemplateChild(PART_HeaderGrid) as ContentControl;
ContentAreaWrapper = GetTemplateChild(PART_ContentAreaWrapper) as Grid;
ContentArea = GetTemplateChild(PART_ContentArea) as ContentControl;
Guard.IsNotNull(HeaderGrid, nameof(HeaderGrid));
Guard.IsNotNull(ContentAreaWrapper, nameof(ContentAreaWrapper));
Guard.IsNotNull(ContentArea, nameof(ContentArea));
var clipComposition = ElementCompositionPreview.GetElementVisual(ContentAreaWrapper);
clipComposition.Clip = clipComposition.Compositor.CreateInsetClip();
ContentAreaWrapper.SizeChanged += ContentSizeChanged;
HeaderGrid.Tapped += HeaderTapped;
}
private void ContentSizeChanged(object sender, SizeChangedEventArgs e)
{
TemplateSettings.ContentHeight = e.NewSize.Height;
TemplateSettings.NegativeContentHeight = -1 * (double)e.NewSize.Height;
}
private void HeaderTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
IsExpanded = !IsExpanded;
}
private static void OnIsExpandedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
if (obj is WinoExpander control)
@@ -40,4 +87,33 @@ namespace Wino.Controls
VisualStateManager.GoToState(this, IsExpanded ? "Expanded" : "Collapsed", true);
}
}
#region Settings
public class WinoExpanderTemplateSettings : DependencyObject
{
public static readonly DependencyProperty HeaderHeightProperty = DependencyProperty.Register(nameof(HeaderHeight), typeof(double), typeof(WinoExpanderTemplateSettings), new PropertyMetadata(0.0));
public static readonly DependencyProperty ContentHeightProperty = DependencyProperty.Register(nameof(ContentHeight), typeof(double), typeof(WinoExpanderTemplateSettings), new PropertyMetadata(0.0));
public static readonly DependencyProperty NegativeContentHeightProperty = DependencyProperty.Register(nameof(NegativeContentHeight), typeof(double), typeof(WinoExpanderTemplateSettings), new PropertyMetadata(0.0));
public double NegativeContentHeight
{
get { return (double)GetValue(NegativeContentHeightProperty); }
set { SetValue(NegativeContentHeightProperty, value); }
}
public double HeaderHeight
{
get { return (double)GetValue(HeaderHeightProperty); }
set { SetValue(HeaderHeightProperty, value); }
}
public double ContentHeight
{
get { return (double)GetValue(ContentHeightProperty); }
set { SetValue(ContentHeightProperty, value); }
}
}
#endregion
}

View File

@@ -13,65 +13,68 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- Header -->
<Grid Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<muxc:AnimatedIcon
xmlns:local="using:Microsoft.UI.Xaml.Controls"
x:Name="ExpandCollapseChevron"
Width="{StaticResource ExpanderChevronGlyphSize}"
Height="{StaticResource ExpanderChevronGlyphSize}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
local:AnimatedIcon.State="NormalOff"
AutomationProperties.AccessibilityView="Raw"
Foreground="{ThemeResource ExpanderChevronForeground}"
RenderTransformOrigin="0.5, 0.5"
Visibility="Collapsed">
<animatedvisuals:AnimatedChevronRightDownSmallVisualSource />
<muxc:AnimatedIcon.FallbackIconSource>
<muxc:FontIconSource
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="{StaticResource ExpanderChevronDownGlyph}"
IsTextScaleFactorEnabled="False" />
</muxc:AnimatedIcon.FallbackIconSource>
<muxc:AnimatedIcon.RenderTransform />
</muxc:AnimatedIcon>
<ContentControl
x:Name="HeaderGrid"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{TemplateBinding Header}" />
</Grid>
<ContentControl
x:Name="ContentArea"
Grid.Row="1"
x:Name="HeaderGrid"
Grid.Column="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{TemplateBinding Content}"
Visibility="Collapsed" />
Background="{TemplateBinding Background}"
Content="{TemplateBinding Header}" />
<!-- Content -->
<Grid x:Name="ContentAreaWrapper" Grid.Row="1">
<ContentControl
x:Name="ContentArea"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Content="{TemplateBinding Content}"
RenderTransformOrigin="0.5,0.5"
Visibility="Collapsed">
<ContentControl.RenderTransform>
<CompositeTransform />
</ContentControl.RenderTransform>
</ContentControl>
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OpenCloseStates">
<VisualState x:Name="Collapsed" />
<VisualState x:Name="Collapsed">
<VisualState.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0.111" Value="Collapsed" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<DiscreteDoubleKeyFrame KeyTime="0" Value="0" />
<SplineDoubleKeyFrame
KeySpline="1.0, 1.0, 0.0, 1.0"
KeyTime="0:0:0.111"
Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeContentHeight}" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState.Storyboard>
</VisualState>
<VisualState x:Name="Expanded">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevron.(controls:AnimatedIcon.State)" Value="NormalOn" />
<Setter Target="ContentArea.Visibility" Value="Visible" />
</VisualState.Setters>
<VisualState.Storyboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentArea" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<DiscreteDoubleKeyFrame KeyTime="0" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.NegativeContentHeight}" />
<SplineDoubleKeyFrame
KeySpline="0.0, 0.0, 0.0, 1.0"
KeyTime="0:0:0.333"
Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState.Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

View File

@@ -6,7 +6,7 @@ namespace Wino.Styles
{
public WinoExpanderStyle()
{
this.InitializeComponent();
InitializeComponent();
}
}
}

View File

@@ -536,8 +536,8 @@
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\WinoExpanderStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Styles\WinoInfoBar.xaml">
<SubType>Designer</SubType>