summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/PageRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/PageRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/PageRenderer.cs80
1 files changed, 80 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/PageRenderer.cs b/Xamarin.Forms.Platform.WinRT/PageRenderer.cs
new file mode 100644
index 00000000..d33ff028
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/PageRenderer.cs
@@ -0,0 +1,80 @@
+´╗┐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();
+ }
+ }
+} \ No newline at end of file