diff --git a/src/Perspex.Controls/Expander.cs b/src/Perspex.Controls/Expander.cs new file mode 100644 index 0000000000..5ac926af47 --- /dev/null +++ b/src/Perspex.Controls/Expander.cs @@ -0,0 +1,74 @@ +using Perspex.Animation; +using Perspex.Controls.Primitives; + +namespace Perspex.Controls +{ + public enum ExpandDirection + { + Down, + Up, + Left, + Right + } + + 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, ":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); + } + + public bool IsExpanded + { + get { return GetValue(IsExpandedProperty); } + set { SetValue(IsExpandedProperty, value); } + } + + public ExpandDirection ExpandDirection + { + get { return GetValue(ExpandDirectionProperty); } + set { SetValue(ExpandDirectionProperty, value); } + } + + 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.Controls/Perspex.Controls.csproj b/src/Perspex.Controls/Perspex.Controls.csproj index 6bd1dd9162..0e8f07767e 100644 --- a/src/Perspex.Controls/Perspex.Controls.csproj +++ b/src/Perspex.Controls/Perspex.Controls.csproj @@ -44,6 +44,7 @@ + diff --git a/src/Perspex.Themes.Default/DefaultTheme.paml b/src/Perspex.Themes.Default/DefaultTheme.paml index 5d8ea78ef1..e3bcf623f1 100644 --- a/src/Perspex.Themes.Default/DefaultTheme.paml +++ b/src/Perspex.Themes.Default/DefaultTheme.paml @@ -23,6 +23,7 @@ + diff --git a/src/Perspex.Themes.Default/Expander.paml b/src/Perspex.Themes.Default/Expander.paml new file mode 100644 index 0000000000..158f6514fd --- /dev/null +++ b/src/Perspex.Themes.Default/Expander.paml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj b/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj index f17c80fe52..cfc8544d16 100644 --- a/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj +++ b/src/Perspex.Themes.Default/Perspex.Themes.Default.csproj @@ -143,6 +143,7 @@ Designer + Designer