Browse Source

Add "UseRenderTransform" property for LayoutTransformControl. Wire up the style animation to use that property.

pull/2453/head
Jumar Macato 8 years ago
parent
commit
29746bbed1
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 49
      src/Avalonia.Controls/LayoutTransformControl.cs
  2. 38
      src/Avalonia.Themes.Default/NotificationArea.xaml

49
src/Avalonia.Controls/LayoutTransformControl.cs

@ -20,6 +20,9 @@ namespace Avalonia.Controls
public static readonly AvaloniaProperty<Transform> LayoutTransformProperty =
AvaloniaProperty.Register<LayoutTransformControl, Transform>(nameof(LayoutTransform));
public static readonly AvaloniaProperty<bool> UseRenderTransformProperty =
AvaloniaProperty.Register<LayoutTransformControl, bool>(nameof(LayoutTransform));
static LayoutTransformControl()
{
ClipToBoundsProperty.OverrideDefaultValue<LayoutTransformControl>(true);
@ -29,6 +32,7 @@ namespace Avalonia.Controls
ChildProperty.Changed
.AddClassHandler<LayoutTransformControl>(x => x.OnChildChanged);
UseRenderTransformProperty.Changed.AddClassHandler<LayoutTransformControl>(x => x.OnUseRenderTransformPropertyChanged);
}
/// <summary>
@ -40,6 +44,15 @@ namespace Avalonia.Controls
set { SetValue(LayoutTransformProperty, value); }
}
/// <summary>
/// Utilize the <see cref="RenderTransformProperty"/> for layout transforms.
/// </summary>
public bool UseRenderTransform
{
get { return GetValue(UseRenderTransformProperty); }
set { SetValue(UseRenderTransformProperty, value); }
}
public IControl TransformRoot => Child;
/// <summary>
@ -134,6 +147,42 @@ namespace Avalonia.Controls
return transformedDesiredSize;
}
IDisposable _renderTransformChangedEvent;
private void OnUseRenderTransformPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
// HACK: In theory, this method and the UseRenderTransform shouldn't exist but
// it's hard to animate this particular control with style animations without
// PropertyPaths.
//
// So until we get that implemented, we'll stick on this not-so-good
// workaround.
var target = e.Sender as LayoutTransformControl;
var shouldUseRenderTransform = (bool)e.NewValue;
if (target != null)
{
if (shouldUseRenderTransform)
{
_renderTransformChangedEvent = RenderTransformProperty.Changed
.Subscribe(
(x) =>
{
var target2 = x.Sender as LayoutTransformControl;
if (target2 != null)
{
target2.LayoutTransform = target2.RenderTransform;
}
});
}
else
{
_renderTransformChangedEvent?.Dispose();
LayoutTransform = null;
}
}
}
private void OnChildChanged(AvaloniaPropertyChangedEventArgs e)
{
if (null != TransformRoot)

38
src/Avalonia.Themes.Default/NotificationArea.xaml

@ -30,20 +30,18 @@
<Setter Property="FontSize" Value="14"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="RenderTransformOrigin" Value="50%,75%"/>
<Setter Property="Height" Value="150"/>
<Setter Property="Template">
<ControlTemplate>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Margin="8,8,0,0">
<ContentControl Content="{TemplateBinding Content}" />
</Border>
<LayoutTransformControl Name="PART_LayoutTransformControl" UseRenderTransform="True">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="8,8,0,0">
<ContentControl MinHeight="150" Content="{TemplateBinding Content}" />
</Border>
</LayoutTransformControl>
</ControlTemplate>
</Setter>
<Style.Animations>
<Animation Duration="0:0:0.45" Easing="QuadraticEaseIn" FillMode="Forward">
<Animation Duration="0:0:0.35" Easing="QuadraticEaseIn" FillMode="Forward">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="0"/>
<Setter Property="TranslateTransform.Y" Value="-20"/>
@ -63,25 +61,27 @@
</Style.Animations>
</Style>
<Style Selector="Notification[IsClosing=true]">
<Style Selector="Notification[IsClosing=true] /template/ LayoutTransformControl#PART_LayoutTransformControl">
<Setter Property="RenderTransformOrigin" Value="50%,0%"/>
<Style.Animations>
<Animation Duration="0:0:0.7" Easing="QuadraticEaseOut" FillMode="Forward">
<Animation Duration="0:0:0.25" Easing="QuadraticEaseOut" FillMode="Forward">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="1"/>
<Setter Property="TranslateTransform.X" Value="0"/>
<Setter Property="ScaleTransform.ScaleY" Value="1"/>
</KeyFrame>
<KeyFrame Cue="50%">
<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="0"/>
<Setter Property="TranslateTransform.X" Value="250"/>
</KeyFrame>
<KeyFrame Cue="60%">
<Setter Property="Height" Value="100"/>
<Setter Property="ScaleTransform.ScaleY" Value="0"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
<Style Selector="Notification[IsClosing=true]">
<Style.Animations>
<Animation Duration="0:0:0.25" Easing="QuadraticEaseOut" FillMode="Forward">
<KeyFrame Cue="100%">
<Setter Property="IsClosed" Value="True"/>
<Setter Property="Opacity" Value="0"/>
<Setter Property="TranslateTransform.X" Value="250"/>
<Setter Property="Height" Value="0"/>
</KeyFrame>
</Animation>
</Style.Animations>

Loading…
Cancel
Save