add DrawerContainer

This commit is contained in:
chenjie02_cd committed 2021-07-26 13:54:40 +08:00
1 parent e7ec39f53a
commit 2c9ef4e24c
5 files changed
+185 -86

No files matched your search

@@ -2,73 +2,140 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
Background="{DynamicResource RegionBrush}">
Background="{DynamicResource RegionBrush}"
Height="400"
Margin="32">
<hc:TransitioningContentControl>
<hc:SimplePanel Margin="22">
<hc:Drawer Name="DrawerLeft" Dock="Left" ShowMode="Push">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Border Style="{StaticResource BorderClip}" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Padding="0">
<hc:SimplePanel>
<hc:Drawer Name="DrawerLeft" Dock="Left" ShowMode="Push">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerTop" Dock="Top" ShowMode="Press">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerRight" MaskCanClose="False">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerBottom" Dock="Bottom" ShowMask="False">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:DrawerContainer>
<Grid VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<hc:Drawer Name="DrawerLeftInContainer" Dock="Left" ShowMode="Push">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerTopInContainer" Dock="Top" ShowMode="Press">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerRightInContainer" MaskCanClose="False">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerBottomInContainer" Dock="Bottom" ShowMask="False">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:ButtonGroup Margin="10" Grid.Row="1" Grid.Column="0">
<ToggleButton Content="Left-Window" IsChecked="{Binding IsOpen,ElementName=DrawerLeft}"/>
<ToggleButton Content="Left-Container" IsChecked="{Binding IsOpen,ElementName=DrawerLeftInContainer}"/>
</hc:ButtonGroup>
<hc:ButtonGroup Margin="10" Grid.Row="0" Grid.Column="1">
<ToggleButton Content="Top-Windows" IsChecked="{Binding IsOpen,ElementName=DrawerTop}"/>
<ToggleButton Content="Top-Container" IsChecked="{Binding IsOpen,ElementName=DrawerTopInContainer}"/>
</hc:ButtonGroup>
<hc:ButtonGroup Margin="10" Grid.Row="1" Grid.Column="2">
<ToggleButton Content="Right-Windows" IsChecked="{Binding IsOpen,ElementName=DrawerRight}"/>
<ToggleButton Content="Right-Container" IsChecked="{Binding IsOpen,ElementName=DrawerRightInContainer}"/>
</hc:ButtonGroup>
<hc:ButtonGroup Margin="10" Grid.Row="2" Grid.Column="1">
<ToggleButton Content="Bottom-Windows" IsChecked="{Binding IsOpen,ElementName=DrawerBottom}"/>
<ToggleButton Content="Bottom-Container" IsChecked="{Binding IsOpen,ElementName=DrawerBottomInContainer}"/>
</hc:ButtonGroup>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerTop" Dock="Top" ShowMode="Press">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerRight" MaskCanClose="False">
<Border Background="{DynamicResource RegionBrush}" Width="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<hc:Drawer Name="DrawerBottom" Dock="Bottom" ShowMask="False">
<Border Background="{DynamicResource RegionBrush}" Height="300" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10,0,0,0" Text="Header" Style="{StaticResource TextBlockTitle}" HorizontalAlignment="Left"/>
<Button Command="hc:ControlCommands.Close" Grid.Row="0" HorizontalAlignment="Right" Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}"/>
</Grid>
</Border>
</hc:Drawer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ToggleButton Margin="10" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="0" Content="Left" IsChecked="{Binding IsOpen,ElementName=DrawerLeft}"/>
<ToggleButton Margin="10" HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" Content="Top" IsChecked="{Binding IsOpen,ElementName=DrawerTop}"/>
<ToggleButton Margin="10" HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="2" Content="Right" IsChecked="{Binding IsOpen,ElementName=DrawerRight}"/>
<ToggleButton Margin="10" HorizontalAlignment="Stretch" Grid.Row="2" Grid.Column="1" Content="Bottom" IsChecked="{Binding IsOpen,ElementName=DrawerBottom}"/>
</Grid>
</hc:SimplePanel>
</hc:DrawerContainer>
</hc:SimplePanel>
</Border>
</hc:TransitioningContentControl>
</UserControl>
@@ -32,9 +32,7 @@ namespace HandyControl.Controls
private AdornerLayer _layer;
private System.Windows.Window _window;
private UIElement _windowContentElement;
private UIElement _contentElement;
private Point _contentRenderTransformOrigin;
@@ -249,7 +247,7 @@ namespace HandyControl.Controls
{
if (!IsOpen)
{
_windowContentElement.SetCurrentValue(RenderTransformOriginProperty, _contentRenderTransformOrigin);
_contentElement.SetCurrentValue(RenderTransformOriginProperty, _contentRenderTransformOrigin);
_layer.Remove(_container);
RaiseEvent(new RoutedEventArgs(ClosedEvent, this));
}
@@ -261,19 +259,42 @@ namespace HandyControl.Controls
private void OnIsOpenChanged(bool isOpen)
{
if (Content == null || DesignerHelper.IsInDesignMode) return;
if (Content == null || DesignerHelper.IsInDesignMode)
{
return;
}
_window = WindowHelper.GetActiveWindow();
if (_window == null) return;
AdornerDecorator decorator;
var parent = VisualHelper.GetParent<DrawerContainer>(this);
if (parent != null)
{
_contentElement = parent.Child;
decorator = parent;
}
else
{
var window = WindowHelper.GetActiveWindow();
if (window == null)
{
return;
}
_windowContentElement = _window.Content as UIElement;
if (_windowContentElement == null) return;
decorator = VisualHelper.GetChild<AdornerDecorator>(window);
_contentElement = window.Content as UIElement;
}
_contentRenderTransformOrigin = _windowContentElement.RenderTransformOrigin;
if (_contentElement == null)
{
return;
}
var decorator = VisualHelper.GetChild<AdornerDecorator>(_window);
_layer = decorator?.AdornerLayer;
if (_layer == null) return;
if (_layer == null)
{
return;
}
_contentRenderTransformOrigin = _contentElement.RenderTransformOrigin;
if (_container == null)
{
@@ -286,7 +307,7 @@ namespace HandyControl.Controls
ShowByPush(isOpen);
break;
case DrawerShowMode.Press:
_windowContentElement.SetCurrentValue(RenderTransformOriginProperty, new Point(0.5, 0.5));
_contentElement.SetCurrentValue(RenderTransformOriginProperty, new Point(0.5, 0.5));
ShowByPress(isOpen);
break;
}
@@ -335,7 +356,7 @@ namespace HandyControl.Controls
case Dock.Left:
case Dock.Right:
animationPropertyName = "(UIElement.RenderTransform).(TranslateTransform.X)";
_windowContentElement.RenderTransform = new TranslateTransform
_contentElement.RenderTransform = new TranslateTransform
{
X = isOpen ? 0 : -_animationLength
};
@@ -343,7 +364,7 @@ namespace HandyControl.Controls
case Dock.Top:
case Dock.Bottom:
animationPropertyName = "(UIElement.RenderTransform).(TranslateTransform.Y)";
_windowContentElement.RenderTransform = new TranslateTransform
_contentElement.RenderTransform = new TranslateTransform
{
Y = isOpen ? 0 : -_animationLength
};
@@ -355,7 +376,7 @@ namespace HandyControl.Controls
var animation = isOpen
? AnimationHelper.CreateAnimation(-_animationLength)
: AnimationHelper.CreateAnimation(0);
Storyboard.SetTarget(animation, _windowContentElement);
Storyboard.SetTarget(animation, _contentElement);
Storyboard.SetTargetProperty(animation, new PropertyPath(animationPropertyName));
_storyboard.Children.Add(animation);
@@ -363,7 +384,7 @@ namespace HandyControl.Controls
private void ShowByPress(bool isOpen)
{
_windowContentElement.RenderTransform = isOpen
_contentElement.RenderTransform = isOpen
? new ScaleTransform()
: new ScaleTransform
{
@@ -374,7 +395,7 @@ namespace HandyControl.Controls
var animationX = isOpen
? AnimationHelper.CreateAnimation(.9)
: AnimationHelper.CreateAnimation(1);
Storyboard.SetTarget(animationX, _windowContentElement);
Storyboard.SetTarget(animationX, _contentElement);
Storyboard.SetTargetProperty(animationX, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));
_storyboard.Children.Add(animationX);
@@ -382,7 +403,7 @@ namespace HandyControl.Controls
var animationY = isOpen
? AnimationHelper.CreateAnimation(.9)
: AnimationHelper.CreateAnimation(1);
Storyboard.SetTarget(animationY, _windowContentElement);
Storyboard.SetTarget(animationY, _contentElement);
Storyboard.SetTargetProperty(animationY, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
_storyboard.Children.Add(animationY);
@@ -0,0 +1,9 @@
using System.Windows.Documents;
namespace HandyControl.Controls
{
public class DrawerContainer : AdornerDecorator
{
}
}
@@ -32,6 +32,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\SplitButton.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Carousel\CarouselItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Dialog\DialogContainer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Drawer\DrawerContainer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\GrowlWindow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageBlock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Input\CheckComboBox\CheckComboBox.cs" />
@@ -40,7 +41,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Input\PinBox.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\DashedBorder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Divider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Drawer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Drawer\Drawer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Empty.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Magnifier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Button\ButtonGroup.cs" />