maui-linux/Xamarin.Forms.Platform.WinRT/PageRenderer.cs

80 строки
1.5 KiB
C#

using System.Collections.ObjectModel;
using Windows.UI.Xaml;
#if WINDOWS_UWP
namespace Xamarin.Forms.Platform.UWP
#else
namespace Xamarin.Forms.Platform.WinRT
#endif
{
public class PageRenderer : VisualElementRenderer<Page, FrameworkElement>
{
bool _disposed;
bool _loaded;
protected override void Dispose(bool disposing)
{
if (!disposing || _disposed)
return;
_disposed = true;
if (Element != null)
{
ReadOnlyCollection<Element> children = Element.LogicalChildren;
for (var i = 0; i < children.Count; i++)
{
var visualChild = children[i] as VisualElement;
visualChild?.Cleanup();
}
Element?.SendDisappearing();
}
base.Dispose();
}
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
e.OldElement.SendDisappearing();
}
if (e.NewElement != null)
{
if (e.OldElement == null)
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
Tracker = new BackgroundTracker<FrameworkElement>(BackgroundProperty);
}
if (_loaded)
e.NewElement.SendAppearing();
}
}
void OnLoaded(object sender, RoutedEventArgs args)
{
var carouselPage = Element?.Parent as CarouselPage;
if (carouselPage != null && carouselPage.Children[0] != Element)
{
return;
}
_loaded = true;
Element?.SendAppearing();
}
void OnUnloaded(object sender, RoutedEventArgs args)
{
_loaded = false;
Element?.SendDisappearing();
}
}
}