Skip to content

Commit

Permalink
chore: optimize demo menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Nov 8, 2022
1 parent ca5c292 commit d787654
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
Background="{StaticResource CloudDrawingBrush}"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
xmlns:hc="https://handyorg.github.io/handycontrol"
x:Class="HandyControlDemo.UserControl.MainWindowContent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="240" MinWidth="240" MaxWidth="400"/>
<ColumnDefinition x:Name="ColumnDefinitionLeft" Width="240" MinWidth="240" MaxWidth="400"/>
<ColumnDefinition MinWidth="200"/>
</Grid.ColumnDefinitions>
<userControl:LeftMainContent/>
<userControl:MainContent Grid.Column="1"/>
<GridSplitter Margin="0,26,0,26" Grid.Column="0" HorizontalAlignment="Right" Width="4" Background="Transparent"/>
<Button x:Name="ButtonShiftOut" Click="OnLeftMainContentShiftOut" hc:IconElement.Geometry="{StaticResource LeftGeometry}" Padding="8 8 0 8" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 26 -16 0" Style="{StaticResource ButtonIconCircular}" />
<userControl:MainContent Grid.Column="1" x:Name="MainContent" />
<userControl:LeftMainContent Grid.Column="0" x:Name="LeftMainContent">
<UIElement.RenderTransform>
<TranslateTransform />
</UIElement.RenderTransform>
</userControl:LeftMainContent>
<GridSplitter x:Name="GridSplitter" Margin="0,26,0,26" Grid.Column="0" HorizontalAlignment="Right" Width="4" Background="Transparent"/>
<Button Grid.Column="0" x:Name="ButtonShiftIn" Visibility="Collapsed" Click="OnLeftMainContentShiftIn" hc:IconElement.Geometry="{StaticResource RightGeometry}" Padding="8 8 0 8" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-12 26 0 0" Style="{StaticResource ButtonIconCircular}" />
</Grid>
</Border>
Original file line number Diff line number Diff line change
@@ -1,9 +1,72 @@
namespace HandyControlDemo.UserControl;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using HandyControl.Tools;
using HandyControl.Tools.Extension;

namespace HandyControlDemo.UserControl;

public partial class MainWindowContent
{
private GridLength _columnDefinitionWidth;

public MainWindowContent()
{
InitializeComponent();
}

private void OnLeftMainContentShiftOut(object sender, RoutedEventArgs e)
{
ButtonShiftOut.Collapse();
GridSplitter.IsEnabled = false;

double targetValue = -ColumnDefinitionLeft.Width.Value;
_columnDefinitionWidth = ColumnDefinitionLeft.Width;

DoubleAnimation animation = AnimationHelper.CreateAnimation(targetValue, milliseconds: 100);
animation.FillBehavior = FillBehavior.Stop;
animation.Completed += OnAnimationCompleted;
LeftMainContent.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animation);

void OnAnimationCompleted(object _, EventArgs args)
{
animation.Completed -= OnAnimationCompleted;
LeftMainContent.RenderTransform.SetCurrentValue(TranslateTransform.XProperty, targetValue);

Grid.SetColumn(MainContent, 0);
Grid.SetColumnSpan(MainContent, 2);

ColumnDefinitionLeft.MinWidth = 0;
ColumnDefinitionLeft.Width = new GridLength();
ButtonShiftIn.Show();
}
}

private void OnLeftMainContentShiftIn(object sender, RoutedEventArgs e)
{
ButtonShiftIn.Collapse();
GridSplitter.IsEnabled = true;

double targetValue = ColumnDefinitionLeft.Width.Value;

DoubleAnimation animation = AnimationHelper.CreateAnimation(targetValue, milliseconds: 100);
animation.FillBehavior = FillBehavior.Stop;
animation.Completed += OnAnimationCompleted;
LeftMainContent.RenderTransform.BeginAnimation(TranslateTransform.XProperty, animation);

void OnAnimationCompleted(object _, EventArgs args)
{
animation.Completed -= OnAnimationCompleted;
LeftMainContent.RenderTransform.SetCurrentValue(TranslateTransform.XProperty, targetValue);

Grid.SetColumn(MainContent, 1);
Grid.SetColumnSpan(MainContent, 1);

ColumnDefinitionLeft.MinWidth = 240;
ColumnDefinitionLeft.Width = _columnDefinitionWidth;
ButtonShiftOut.Show();
}
}
}

0 comments on commit d787654

Please sign in to comment.