csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
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.
66 lines
2.1 KiB
66 lines
2.1 KiB
using System;
|
|
using Avalonia.LogicalTree;
|
|
using Avalonia.UnitTests;
|
|
using Xunit;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Animation;
|
|
|
|
namespace Avalonia.Controls.UnitTests
|
|
{
|
|
public class TransitioningContentControlTests
|
|
{
|
|
[Fact]
|
|
public void Old_Content_Shuold_Be_Removed__From_Logical_Tree_After_Out_Animation()
|
|
{
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
{
|
|
var testTransition = new TestTransition();
|
|
|
|
var target = new TransitioningContentControl();
|
|
target.PageTransition = testTransition;
|
|
|
|
var root = new TestRoot() { Child = target };
|
|
|
|
var oldControl = new Control();
|
|
var newControl = new Control();
|
|
|
|
target.Content = oldControl;
|
|
Threading.Dispatcher.UIThread.RunJobs();
|
|
|
|
Assert.Equal(target, oldControl.GetLogicalParent());
|
|
Assert.Equal(null, newControl.GetLogicalParent());
|
|
|
|
testTransition.BeginTransition += isFrom =>
|
|
{
|
|
// Old out
|
|
if (isFrom)
|
|
{
|
|
Assert.Equal(target, oldControl.GetLogicalParent());
|
|
Assert.Equal(null, newControl.GetLogicalParent());
|
|
}
|
|
// New in
|
|
else
|
|
{
|
|
Assert.Equal(null, oldControl.GetLogicalParent());
|
|
Assert.Equal(target, newControl.GetLogicalParent());
|
|
}
|
|
};
|
|
|
|
target.Content = newControl;
|
|
Threading.Dispatcher.UIThread.RunJobs();
|
|
}
|
|
}
|
|
}
|
|
public class TestTransition : IPageTransition
|
|
{
|
|
public event Action<bool> BeginTransition;
|
|
|
|
public Task Start(Visual from, Visual to, bool forward, CancellationToken cancellationToken)
|
|
{
|
|
bool isFrom = from != null && to == null;
|
|
BeginTransition?.Invoke(isFrom);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|
|
|