A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.5 KiB

using System;
using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using Avalonia.Styling;
namespace ControlCatalog.Pages;
public partial class HomePage : ContentPage
{
public HomePage()
{
InitializeComponent();
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
StartFloatingAnimation(BannerLogo1, 12, 8, TimeSpan.FromSeconds(12));
StartFloatingAnimation(BannerLogo2, -14, 8, TimeSpan.FromSeconds(10));
StartFloatingAnimation(BannerLogo3, -12, -12, TimeSpan.FromSeconds(14));
StartFloatingAnimation(BannerLogo4, 12, -8, TimeSpan.FromSeconds(11));
}
private static void StartFloatingAnimation(Control target, double dx, double dy, TimeSpan duration)
{
var transform = new TranslateTransform();
target.RenderTransform = transform;
var animation = new Animation
{
Duration = duration,
IterationCount = IterationCount.Infinite,
Children =
{
new KeyFrame
{
Cue = new Cue(0d),
Setters =
{
new Setter(TranslateTransform.XProperty, 0d),
new Setter(TranslateTransform.YProperty, 0d),
}
},
new KeyFrame
{
Cue = new Cue(0.5d),
Setters =
{
new Setter(TranslateTransform.XProperty, dx),
new Setter(TranslateTransform.YProperty, dy),
}
},
new KeyFrame
{
Cue = new Cue(1d),
Setters =
{
new Setter(TranslateTransform.XProperty, 0d),
new Setter(TranslateTransform.YProperty, 0d),
}
},
}
};
_ = animation.RunAsync(target);
}
private void UniformGrid_OnSizeChanged(object? sender, SizeChangedEventArgs e)
{
if (sender is not UniformGrid grid)
return;
const int minItemWidth = 248;
grid.Columns = Math.Max(
1,
(int)((e.NewSize.Width + grid.ColumnSpacing) / (minItemWidth + grid.ColumnSpacing)));
}
}