add Drawer demo
This commit is contained in:
1 parent
453839e763
commit
d145dee9c9
29 files changed
+768
-566
No files matched your search
@@ -43,7 +43,7 @@ namespace HandyControl.Controls
|
||||
}));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) =>
|
||||
{
|
||||
SetCurrentValue(ValueProperty, 0d);
|
||||
SetCurrentValue(ValueProperty, ValueBoxes.Double0Box);
|
||||
_textBox.Text = string.Empty;
|
||||
}));
|
||||
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Interactivity;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[ContentProperty("Content")]
|
||||
public class Drawer : FrameworkElement
|
||||
{
|
||||
private AdornerContainer _container;
|
||||
|
||||
private ContentControl _animateControl;
|
||||
|
||||
private TranslateTransform _translateTransform;
|
||||
|
||||
private double _animationLength;
|
||||
|
||||
private DependencyProperty _animationProperty;
|
||||
|
||||
private FrameworkElement _maskElement;
|
||||
|
||||
private AdornerLayer _layer;
|
||||
|
||||
public Drawer()
|
||||
{
|
||||
Loaded += Drawer_Loaded;
|
||||
Unloaded += Drawer_Unloaded;
|
||||
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Close, (s, e) => SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox)));
|
||||
}
|
||||
|
||||
private void Drawer_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (IsOpen)
|
||||
{
|
||||
OnIsOpenChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Drawer_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loaded -= Drawer_Loaded;
|
||||
if (_maskElement != null)
|
||||
{
|
||||
_maskElement.PreviewMouseLeftButtonDown -= MaskElement_PreviewMouseLeftButtonDown;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
|
||||
"IsOpen", typeof(bool), typeof(Drawer), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsOpenChanged));
|
||||
|
||||
private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Drawer) d;
|
||||
ctl.OnIsOpenChanged((bool)e.NewValue);
|
||||
}
|
||||
|
||||
public bool IsOpen
|
||||
{
|
||||
get => (bool) GetValue(IsOpenProperty);
|
||||
set => SetValue(IsOpenProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaskCanCloseProperty = DependencyProperty.Register(
|
||||
"MaskCanClose", typeof(bool), typeof(Drawer), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public bool MaskCanClose
|
||||
{
|
||||
get => (bool) GetValue(MaskCanCloseProperty);
|
||||
set => SetValue(MaskCanCloseProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowMaskProperty = DependencyProperty.Register(
|
||||
"ShowMask", typeof(bool), typeof(Drawer), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public bool ShowMask
|
||||
{
|
||||
get => (bool) GetValue(ShowMaskProperty);
|
||||
set => SetValue(ShowMaskProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty DockProperty = DependencyProperty.Register(
|
||||
"Dock", typeof(Dock), typeof(Drawer), new PropertyMetadata(default(Dock)));
|
||||
|
||||
public Dock Dock
|
||||
{
|
||||
get => (Dock) GetValue(DockProperty);
|
||||
set => SetValue(DockProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ShowModeProperty = DependencyProperty.Register(
|
||||
"ShowMode", typeof(DrawerShowMode), typeof(Drawer), new PropertyMetadata(default(DrawerShowMode)));
|
||||
|
||||
public DrawerShowMode ShowMode
|
||||
{
|
||||
get => (DrawerShowMode) GetValue(ShowModeProperty);
|
||||
set => SetValue(ShowModeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaskBrushProperty = DependencyProperty.Register(
|
||||
"MaskBrush", typeof(Brush), typeof(Drawer), new PropertyMetadata(default(Brush)));
|
||||
|
||||
public Brush MaskBrush
|
||||
{
|
||||
get => (Brush) GetValue(MaskBrushProperty);
|
||||
set => SetValue(MaskBrushProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
|
||||
"Content", typeof(object), typeof(Drawer), new PropertyMetadata(default(object)));
|
||||
|
||||
public object Content
|
||||
{
|
||||
get => GetValue(ContentProperty);
|
||||
set => SetValue(ContentProperty, value);
|
||||
}
|
||||
|
||||
private void OnIsOpenChanged(bool isOpen)
|
||||
{
|
||||
if (Content == null) return;
|
||||
|
||||
var window = WindowHelper.GetActiveWindow();
|
||||
if (window == null) return;
|
||||
|
||||
var decorator = VisualHelper.GetChild<AdornerDecorator>(window);
|
||||
_layer = decorator?.AdornerLayer;
|
||||
if (_layer == null) return;
|
||||
|
||||
if (_container == null)
|
||||
{
|
||||
CreateContainer();
|
||||
}
|
||||
|
||||
switch (ShowMode)
|
||||
{
|
||||
case DrawerShowMode.Cover:
|
||||
ShowByCover(isOpen);
|
||||
break;
|
||||
case DrawerShowMode.Push:
|
||||
ShowByPush(isOpen);
|
||||
break;
|
||||
case DrawerShowMode.Press:
|
||||
ShowByPress(isOpen);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowByCover(bool isOpen)
|
||||
{
|
||||
if (isOpen)
|
||||
{
|
||||
_maskElement?.BeginAnimation(OpacityProperty, AnimationHelper.CreateAnimation(1));
|
||||
_translateTransform.BeginAnimation(_animationProperty, AnimationHelper.CreateAnimation(0));
|
||||
_layer.Add(_container);
|
||||
}
|
||||
else
|
||||
{
|
||||
var animation = AnimationHelper.CreateAnimation(_animationLength);
|
||||
animation.Completed += (s, e) => _layer.Remove(_container);
|
||||
_maskElement?.BeginAnimation(OpacityProperty, AnimationHelper.CreateAnimation(0));
|
||||
_translateTransform.BeginAnimation(_animationProperty, animation);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowByPush(bool isOpen)
|
||||
{
|
||||
if (isOpen)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowByPress(bool isOpen)
|
||||
{
|
||||
if (isOpen)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateContainer()
|
||||
{
|
||||
_translateTransform = new TranslateTransform();
|
||||
_animateControl = new ContentControl
|
||||
{
|
||||
Content = Content,
|
||||
RenderTransform = _translateTransform,
|
||||
DataContext = this
|
||||
};
|
||||
var panel = new SimplePanel
|
||||
{
|
||||
ClipToBounds = true
|
||||
};
|
||||
|
||||
if (ShowMask)
|
||||
{
|
||||
_maskElement = new Border
|
||||
{
|
||||
Background = MaskBrush,
|
||||
Opacity = 0
|
||||
};
|
||||
_maskElement.PreviewMouseLeftButtonDown += MaskElement_PreviewMouseLeftButtonDown;
|
||||
panel.Children.Add(_maskElement);
|
||||
}
|
||||
|
||||
_animateControl.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
var size = _animateControl.DesiredSize;
|
||||
|
||||
switch (Dock)
|
||||
{
|
||||
case Dock.Left:
|
||||
_animateControl.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
_animateControl.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
_translateTransform.X = -size.Width;
|
||||
_animationLength = -size.Width;
|
||||
_animationProperty = TranslateTransform.XProperty;
|
||||
break;
|
||||
case Dock.Top:
|
||||
_animateControl.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
_animateControl.VerticalAlignment = VerticalAlignment.Top;
|
||||
_translateTransform.Y = -size.Height;
|
||||
_animationLength = -size.Height;
|
||||
_animationProperty = TranslateTransform.YProperty;
|
||||
break;
|
||||
case Dock.Right:
|
||||
_animateControl.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
_animateControl.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
_translateTransform.X = size.Width;
|
||||
_animationLength = size.Width;
|
||||
_animationProperty = TranslateTransform.XProperty;
|
||||
break;
|
||||
case Dock.Bottom:
|
||||
_animateControl.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
_animateControl.VerticalAlignment = VerticalAlignment.Bottom;
|
||||
_translateTransform.Y = size.Height;
|
||||
_animationLength = size.Height;
|
||||
_animationProperty = TranslateTransform.YProperty;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
panel.Children.Add(_animateControl);
|
||||
_container = new AdornerContainer(_layer)
|
||||
{
|
||||
Child = panel,
|
||||
ClipToBounds = true
|
||||
};
|
||||
}
|
||||
|
||||
private void MaskElement_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (MaskCanClose)
|
||||
{
|
||||
SetCurrentValue(IsOpenProperty, ValueBoxes.FalseBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@ namespace HandyControl.Controls
|
||||
HeaderPanel.ForceUpdate = true;
|
||||
HeaderPanel.Measure(new Size(HeaderPanel.DesiredSize.Width, ActualHeight));
|
||||
HeaderPanel.ForceUpdate = false;
|
||||
SetCurrentValue(SelectedIndexProperty, 0);
|
||||
SetCurrentValue(SelectedIndexProperty, ValueBoxes.Int0Box);
|
||||
}
|
||||
|
||||
item.IsSelected = true;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum DrawerShowMode
|
||||
{
|
||||
Cover,
|
||||
Push,
|
||||
Press
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Growl\GrowlWindow.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Image\ImageBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Divider.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Drawer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Magnifier.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ButtonGroup.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Card.cs" />
|
||||
@@ -38,6 +39,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\RunningBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\DrawerShowMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HatchStyle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HitMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\ShowAnimation.cs" />
|
||||
@@ -386,6 +388,14 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Drawer.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\DrawerBaseStyle.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Poptip.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Border.xaml" />
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<Style x:Key="DrawerBaseStyle" TargetType="controls:Drawer">
|
||||
<Setter Property="Dock" Value="Right"/>
|
||||
<Setter Property="MaskBrush" Value="{DynamicResource DarkOpacityBrush}"/>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,10 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Base/DrawerBaseStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style BasedOn="{StaticResource DrawerBaseStyle}" TargetType="controls:Drawer"/>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -77,6 +77,7 @@
|
||||
<ResourceDictionary Source="SplitButton.xaml"/>
|
||||
<ResourceDictionary Source="Divider.xaml"/>
|
||||
<ResourceDictionary Source="Poptip.xaml"/>
|
||||
<ResourceDictionary Source="Drawer.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in new issue
Block a user