Browse Source

expander some code refactoring

pull/367/head
donandren 11 years ago
parent
commit
440fbf44fc
  1. 59
      src/Perspex.Controls/Expander.cs
  2. 10
      src/Perspex.Themes.Default/Expander.paml

59
src/Perspex.Controls/Expander.cs

@ -13,57 +13,62 @@ namespace Perspex.Controls
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()
{
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<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
{
get { return GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public static readonly PerspexProperty<ExpandDirection> ExpandDirectionProperty = PerspexProperty.Register<Expander, ExpandDirection>(nameof(ExpandDirection), ExpandDirection.Down);
public ExpandDirection ExpandDirection
{
get { return GetValue(ExpandDirectionProperty); }
set { SetValue(ExpandDirectionProperty, value); }
}
public static readonly PerspexProperty<IPageTransition> ContentTransitionProperty = PerspexProperty.Register<Expander, IPageTransition>(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);
}
}
}
}
}

10
src/Perspex.Themes.Default/Expander.paml

@ -95,27 +95,27 @@
<Style Selector="Expander /template/ ToggleButton#PART_toggle:pointerover /template/ Border">
<Setter Property="BorderBrush" Value="#ffaaaaaa" />
</Style>
<Style Selector="Expander:ExpandDirectionDown:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Style Selector="Expander:down:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Setter Property="RenderTransform">
<RotateTransform Angle="90" />
</Setter>
</Style>
<Style Selector="Expander:ExpandDirectionUp:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Style Selector="Expander:up:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Setter Property="RenderTransform">
<RotateTransform Angle="-90" />
</Setter>
</Style>
<Style Selector="Expander:ExpandDirectionLeft:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Style Selector="Expander:left:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Setter Property="RenderTransform">
<RotateTransform Angle="180" />
</Setter>
</Style>
<Style Selector="Expander:ExpandDirectionRight /template/ ToggleButton#PART_toggle /template/ Path">
<Style Selector="Expander:right /template/ ToggleButton#PART_toggle /template/ Path">
<Setter Property="RenderTransform">
<RotateTransform Angle="180" />
</Setter>
</Style>
<Style Selector="Expander:ExpandDirectionRight:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Style Selector="Expander:right:expanded /template/ ToggleButton#PART_toggle /template/ Path">
<Setter Property="RenderTransform">
<RotateTransform Angle="0" />
</Setter>

Loading…
Cancel
Save