From 0d1ad4c6dd55b93a2f2c8e528c582fa7f2065166 Mon Sep 17 00:00:00 2001 From: SlimeNull Date: Mon, 15 Apr 2024 10:55:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20StackPanel=20?= =?UTF-8?q?=E5=9C=A8=E5=85=83=E7=B4=A0=20Visibility=20=E4=B8=BA=20Collapse?= =?UTF-8?q?d=20=E7=9A=84=E6=97=B6=E5=80=99,=20Spacing=20=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EleCho.WpfSuite/Panels/FlexPanel.cs | 2 +- EleCho.WpfSuite/Panels/StackPanel.cs | 15 +++- EleCho.WpfSuite/Panels/WrapPanel.cs | 26 +++++-- WpfTest/MainWindow.xaml | 17 ++++- WpfTest/MainWindow.xaml.cs | 30 +++++++- WpfTest/Tests/CollectionTestPage.xaml | 104 ++++++++++++++++++++++---- WpfTest/Tests/TempPage.xaml | 2 +- WpfTest/WpfTest.csproj | 1 + 8 files changed, 162 insertions(+), 35 deletions(-) diff --git a/EleCho.WpfSuite/Panels/FlexPanel.cs b/EleCho.WpfSuite/Panels/FlexPanel.cs index 67665bc..29cc8ec 100644 --- a/EleCho.WpfSuite/Panels/FlexPanel.cs +++ b/EleCho.WpfSuite/Panels/FlexPanel.cs @@ -91,7 +91,7 @@ public double CrossSpacing public static readonly DependencyProperty ItemsAlignmentProperty = DependencyProperty.Register(nameof(ItemsAlignment), typeof(FlexItemsAlignment), typeof(FlexPanel), - new FrameworkPropertyMetadata(default(FlexItemsAlignment), FrameworkPropertyMetadataOptions.AffectsMeasure)); + new FrameworkPropertyMetadata(FlexItemsAlignment.Stretch, FrameworkPropertyMetadataOptions.AffectsMeasure)); public static readonly DependencyProperty UniformGrowProperty = DependencyProperty.Register(nameof(UniformGrow), typeof(double), typeof(FlexPanel), diff --git a/EleCho.WpfSuite/Panels/StackPanel.cs b/EleCho.WpfSuite/Panels/StackPanel.cs index 872beb8..51c0e1e 100644 --- a/EleCho.WpfSuite/Panels/StackPanel.cs +++ b/EleCho.WpfSuite/Panels/StackPanel.cs @@ -34,7 +34,9 @@ protected override Size MeasureOverride(Size availableSize) var childDesiredSize = child.DesiredSize; panelDesiredSize.Height += childDesiredSize.Height; - panelDesiredSize.Height += spacing; + + if (child.Visibility != Visibility.Collapsed) + panelDesiredSize.Height += spacing; if (childDesiredSize.Width > panelDesiredSize.Width) panelDesiredSize.Width = childDesiredSize.Width; @@ -54,7 +56,9 @@ protected override Size MeasureOverride(Size availableSize) var childDesiredSize = child.DesiredSize; panelDesiredSize.Width += childDesiredSize.Width; - panelDesiredSize.Width += spacing; + + if (child.Visibility != Visibility.Collapsed) + panelDesiredSize.Width += spacing; if (childDesiredSize.Height > panelDesiredSize.Height) panelDesiredSize.Height = childDesiredSize.Height; @@ -83,7 +87,9 @@ protected override Size ArrangeOverride(Size finalSize) child.Arrange(new Rect(0, offset, finalSize.Width, childDesiredSize.Height)); offset += childDesiredSize.Height; - offset += spacing; + + if (child.Visibility != Visibility.Collapsed) + offset += spacing; } } else @@ -95,7 +101,8 @@ protected override Size ArrangeOverride(Size finalSize) child.Arrange(new Rect(offset, 0, childDesiredSize.Width, finalSize.Height)); offset += childDesiredSize.Width; - offset += spacing; + if (child.Visibility != Visibility.Collapsed) + offset += spacing; } } diff --git a/EleCho.WpfSuite/Panels/WrapPanel.cs b/EleCho.WpfSuite/Panels/WrapPanel.cs index 49236e7..d6c552a 100644 --- a/EleCho.WpfSuite/Panels/WrapPanel.cs +++ b/EleCho.WpfSuite/Panels/WrapPanel.cs @@ -70,7 +70,9 @@ protected override Size MeasureOverride(Size availableSize) var childHeight = childHeightGetter.Invoke(childDesiredSize); offsetX += childWidth; - offsetX += horizontalSpacing; + + if (child.Visibility != Visibility.Collapsed) + offsetX += horizontalSpacing; if (offsetX > availableSize.Width) { @@ -113,11 +115,13 @@ protected override Size MeasureOverride(Size availableSize) var childHeight = childHeightGetter.Invoke(childDesiredSize); offsetY += childHeight; - offsetY += verticalSpacing; + + if (child.Visibility != Visibility.Collapsed) + offsetY += verticalSpacing; if (offsetY > availableSize.Height) { - currentLineLength = offsetY -horizontalSpacing - childHeight - verticalSpacing; + currentLineLength = offsetY - horizontalSpacing - childHeight - verticalSpacing; if (currentLineLength > maxLineLength) maxLineLength = currentLineLength; @@ -171,7 +175,9 @@ protected override Size ArrangeOverride(Size finalSize) var childHeight = childHeightGetter.Invoke(childDesiredSize); tempOffset += childWidth; - tempOffset += horizontalSpacing; + + if (child.Visibility != Visibility.Collapsed) + tempOffset += horizontalSpacing; if (tempOffset - horizontalSpacing > finalSize.Width) { @@ -224,7 +230,9 @@ protected override Size ArrangeOverride(Size finalSize) var childHeight = childHeightGetter.Invoke(childDesiredSize); tempOffset += childHeight; - tempOffset += verticalSpacing; + + if (child.Visibility != Visibility.Collapsed) + tempOffset += verticalSpacing; if (tempOffset - verticalSpacing > finalSize.Height) { @@ -293,7 +301,9 @@ static void ArrangeLineHorizontal( lineChild.Arrange(new Rect(currentLineOffsetX + lineChildOffset, currentLineOffsetY, lineChildWidth, currentLineSize)); lineChildOffset += lineChildWidth; - lineChildOffset += spacing; + + if (lineChild.Visibility != Visibility.Collapsed) + lineChildOffset += spacing; } } @@ -320,7 +330,9 @@ static void ArrangeLineVertical( lineChild.Arrange(new Rect(currentLineOffsetX, currentLineOffsetY + lineChildOffset, currentLineSize, lineChildHeight)); lineChildOffset += lineChildHeight; - lineChildOffset += spacing; + + if (lineChild.Visibility != Visibility.Collapsed) + lineChildOffset += spacing; } } } diff --git a/WpfTest/MainWindow.xaml b/WpfTest/MainWindow.xaml index 760f973..102f65d 100644 --- a/WpfTest/MainWindow.xaml +++ b/WpfTest/MainWindow.xaml @@ -5,10 +5,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfTest" xmlns:ws="https://github.com/OrgEleCho/EleCho.WpfSuite" + xmlns:b="http://schemas.microsoft.com/xaml/behaviors" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:hc="https://handyorg.github.io/handycontrol" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800" + Title="MainWindow" Height="550" Width="800" + Loaded="Window_Loaded" d:DataContext="{d:DesignInstance Type=local:MainWindow}"> @@ -16,8 +18,10 @@ - @@ -31,6 +35,11 @@ + NavigationUIVisibility="Hidden" + Navigated="AppFrame_Navigated"> + + + + diff --git a/WpfTest/MainWindow.xaml.cs b/WpfTest/MainWindow.xaml.cs index 3dbf623..8ec50a0 100644 --- a/WpfTest/MainWindow.xaml.cs +++ b/WpfTest/MainWindow.xaml.cs @@ -6,6 +6,7 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; @@ -41,18 +42,23 @@ public MainWindow() }, new NavigationItem() { - Title = "Temp test", + Title = "TextBox test", Description = "", - PageType = typeof(TempPage) + PageType = typeof(TextBoxTestPage) }, new NavigationItem() { - Title = "TextBox test", + Title = "Temp test", Description = "", - PageType = typeof(TextBoxTestPage) + PageType = typeof(TempPage) }, }; + private void Window_Loaded(object sender, RoutedEventArgs e) + { + AppNavigations.SelectedItem = NavigationItems.FirstOrDefault(); + } + private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (sender is not ListBox listBox || @@ -62,5 +68,21 @@ private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e var page = Activator.CreateInstance(navigationItem.PageType); AppFrame.Navigate(page); } + + private void AppFrame_Navigated(object sender, NavigationEventArgs e) + { + DoubleAnimation doubleAnimation = new DoubleAnimation() + { + From = 10, + To = 0, + Duration = new Duration(TimeSpan.FromMilliseconds(200)), + EasingFunction = new CircleEase() + { + EasingMode = EasingMode.EaseOut + } + }; + + AppFrame.RenderTransform.BeginAnimation(TranslateTransform.YProperty, doubleAnimation); + } } } \ No newline at end of file diff --git a/WpfTest/Tests/CollectionTestPage.xaml b/WpfTest/Tests/CollectionTestPage.xaml index f2cc037..924cc9d 100644 --- a/WpfTest/Tests/CollectionTestPage.xaml +++ b/WpfTest/Tests/CollectionTestPage.xaml @@ -1,12 +1,13 @@  @@ -17,17 +18,92 @@ - - - + + + + - -