|
|
@ -13,57 +13,62 @@ namespace Perspex.Controls |
|
|
|
|
|
|
|
|
public class Expander : HeaderedContentControl |
|
|
public class Expander : HeaderedContentControl |
|
|
{ |
|
|
{ |
|
|
|
|
|
public static readonly PerspexProperty<bool> IsExpandedProperty = |
|
|
|
|
|
PerspexProperty.Register<Expander, bool>(nameof(IsExpanded), true); |
|
|
|
|
|
|
|
|
|
|
|
public static readonly PerspexProperty<ExpandDirection> ExpandDirectionProperty = |
|
|
|
|
|
PerspexProperty.Register<Expander, ExpandDirection>(nameof(ExpandDirection), ExpandDirection.Down); |
|
|
|
|
|
|
|
|
|
|
|
public static readonly PerspexProperty<IPageTransition> ContentTransitionProperty = |
|
|
|
|
|
PerspexProperty.Register<Expander, IPageTransition>(nameof(ContentTransition)); |
|
|
|
|
|
|
|
|
static Expander() |
|
|
static Expander() |
|
|
{ |
|
|
{ |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Down, ":ExpandDirectionDown"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Down, ":down"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Up, ":ExpandDirectionUp"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Up, ":up"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Left, ":ExpandDirectionLeft"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Left, ":left"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Right, ":ExpandDirectionRight"); |
|
|
PseudoClass(ExpandDirectionProperty, d => d == ExpandDirection.Right, ":right"); |
|
|
|
|
|
|
|
|
PseudoClass(IsExpandedProperty, ":expanded"); |
|
|
PseudoClass(IsExpandedProperty, ":expanded"); |
|
|
|
|
|
|
|
|
IsExpandedProperty.Changed.AddClassHandler<Expander>(x => x.OnIsExpandedChanged); |
|
|
IsExpandedProperty.Changed.AddClassHandler<Expander>(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<bool> IsExpandedProperty = PerspexProperty.Register<Expander, bool>(nameof(IsExpanded), true); |
|
|
|
|
|
|
|
|
|
|
|
public bool IsExpanded |
|
|
public bool IsExpanded |
|
|
{ |
|
|
{ |
|
|
get { return GetValue(IsExpandedProperty); } |
|
|
get { return GetValue(IsExpandedProperty); } |
|
|
set { SetValue(IsExpandedProperty, value); } |
|
|
set { SetValue(IsExpandedProperty, value); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static readonly PerspexProperty<ExpandDirection> ExpandDirectionProperty = PerspexProperty.Register<Expander, ExpandDirection>(nameof(ExpandDirection), ExpandDirection.Down); |
|
|
|
|
|
|
|
|
|
|
|
public ExpandDirection ExpandDirection |
|
|
public ExpandDirection ExpandDirection |
|
|
{ |
|
|
{ |
|
|
get { return GetValue(ExpandDirectionProperty); } |
|
|
get { return GetValue(ExpandDirectionProperty); } |
|
|
set { SetValue(ExpandDirectionProperty, value); } |
|
|
set { SetValue(ExpandDirectionProperty, value); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static readonly PerspexProperty<IPageTransition> ContentTransitionProperty = PerspexProperty.Register<Expander, IPageTransition>(nameof(ContentTransition)); |
|
|
|
|
|
|
|
|
|
|
|
public IPageTransition ContentTransition |
|
|
public IPageTransition ContentTransition |
|
|
{ |
|
|
{ |
|
|
get { return GetValue(ContentTransitionProperty); } |
|
|
get { return GetValue(ContentTransitionProperty); } |
|
|
set { SetValue(ContentTransitionProperty, value); } |
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |