From 440fbf44fc38346dbdbc14e096af0e9a16854b4a Mon Sep 17 00:00:00 2001 From: donandren Date: Fri, 18 Dec 2015 19:42:25 +0200 Subject: [PATCH] expander some code refactoring --- src/Perspex.Controls/Expander.cs | 59 +++++++++++++----------- src/Perspex.Themes.Default/Expander.paml | 10 ++-- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/Perspex.Controls/Expander.cs b/src/Perspex.Controls/Expander.cs index 5d96107ac8..5ac926af47 100644 --- a/src/Perspex.Controls/Expander.cs +++ b/src/Perspex.Controls/Expander.cs @@ -13,57 +13,62 @@ namespace Perspex.Controls public class Expander : HeaderedContentControl { + public static readonly PerspexProperty IsExpandedProperty = + PerspexProperty.Register(nameof(IsExpanded), true); + + public static readonly PerspexProperty ExpandDirectionProperty = + PerspexProperty.Register(nameof(ExpandDirection), ExpandDirection.Down); + + public static readonly PerspexProperty ContentTransitionProperty = + PerspexProperty.Register(nameof(ContentTransition)); + static Expander() { - PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Down, ":ExpandDirectionDown"); - PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Up, ":ExpandDirectionUp"); - PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Left, ":ExpandDirectionLeft"); - PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Right, ":ExpandDirectionRight"); + PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Down, ":down"); + PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Up, ":up"); + PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Left, ":left"); + PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Right, ":right"); PseudoClass(IsExpandedProperty, ":expanded"); IsExpandedProperty.Changed.AddClassHandler(x => x.OnIsExpandedChanged); } - protected virtual void OnIsExpandedChanged(PerspexPropertyChangedEventArgs e) - { - IVisual visualContent = Presenter; - if (Content != null && ContentTransition != null && visualContent != null) - { - bool forward = ExpandDirection == ExpandDirection.Left || ExpandDirection == ExpandDirection.Up; - if (IsExpanded) - { - ContentTransition.Start(null, visualContent, forward); - } - else - { - ContentTransition.Start(visualContent, null, !forward); - } - } - } - - public static readonly PerspexProperty IsExpandedProperty = PerspexProperty.Register(nameof(IsExpanded), true); - public bool IsExpanded { get { return GetValue(IsExpandedProperty); } set { SetValue(IsExpandedProperty, value); } } - public static readonly PerspexProperty ExpandDirectionProperty = PerspexProperty.Register(nameof(ExpandDirection), ExpandDirection.Down); - public ExpandDirection ExpandDirection { get { return GetValue(ExpandDirectionProperty); } set { SetValue(ExpandDirectionProperty, value); } } - public static readonly PerspexProperty ContentTransitionProperty = PerspexProperty.Register(nameof(ContentTransition)); - public IPageTransition ContentTransition { get { return GetValue(ContentTransitionProperty); } set { SetValue(ContentTransitionProperty, value); } } + + protected virtual void OnIsExpandedChanged(PerspexPropertyChangedEventArgs e) + { + IVisual visualContent = Presenter; + + if (Content != null && ContentTransition != null && visualContent != null) + { + bool forward = ExpandDirection == ExpandDirection.Left || + ExpandDirection == ExpandDirection.Up; + if (IsExpanded) + { + ContentTransition.Start(null, visualContent, forward); + } + else + { + ContentTransition.Start(visualContent, null, !forward); + } + } + } } } \ No newline at end of file diff --git a/src/Perspex.Themes.Default/Expander.paml b/src/Perspex.Themes.Default/Expander.paml index c1cb99248d..158f6514fd 100644 --- a/src/Perspex.Themes.Default/Expander.paml +++ b/src/Perspex.Themes.Default/Expander.paml @@ -95,27 +95,27 @@ - - - - -