Beispiel #1
0
        public static void AnimateBackItemToList(ListViewBase list, object lastSelectedItem, ConnectedAnimation connectedAnimation)
        {
            list.ScrollIntoView(lastSelectedItem);

            if (list.GetType() == typeof(ListView))
            {
                var item = (ListViewItem)list.ContainerFromItem(lastSelectedItem);
                if (item == null)
                {
                    connectedAnimation.Cancel(); return;
                }

                var pane = (FrameworkElement)item.ContentTemplateRoot;

                var image = (Image)pane.FindName("PhotoImage");
                if (image == null)
                {
                    connectedAnimation.Cancel(); return;
                }

                image.Opacity = 0;
                image.Loaded += (_s, _e) => {
                    image.Opacity = 1;
                    connectedAnimation.TryStart(image);
                };
            }
            else if (list.GetType() == typeof(AdaptiveGridView) || list.GetType() == typeof(GridView))
            {
                var item = (GridViewItem)list.ContainerFromItem(lastSelectedItem);
                if (item == null)
                {
                    connectedAnimation.Cancel(); return;
                }

                var pane = (FrameworkElement)item.ContentTemplateRoot;

                var image = (Image)pane.FindName("PhotoImage");
                if (image == null)
                {
                    connectedAnimation.Cancel(); return;
                }

                image.Opacity = 0;
                image.Loaded += (_s, _e) => {
                    image.Opacity = 1;
                    connectedAnimation.TryStart(image);
                };
            }
        }
Beispiel #2
0
        private void OnLoaded(AdaptiveGridView adaptiveGrid)
        {
            IsMultiselectionEnable = false;

            if (adaptiveGrid == null || LastSelectedItem == null)
            {
                return;
            }

            var selectedItem = Items.FirstOrDefault(item => item.Item.Id == LastSelectedItem.Item.Id);

            if (selectedItem == null)
            {
                return;
            }

            ConnectedAnimation animation = ConnectedAnimationService.GetForCurrentView().GetAnimation(Constants.ConnectedAnimationKey);

            if (animation != null)
            {
                adaptiveGrid.ScrollIntoView(selectedItem, ScrollIntoViewAlignment.Default);
                adaptiveGrid.UpdateLayout();

                var containerObject = adaptiveGrid.ContainerFromItem(selectedItem);

                if (containerObject is GridViewItem container)
                {
                    var root  = (FrameworkElement)container.ContentTemplateRoot;
                    var image = (Image)root.FindName("SourceImage");
                    animation.TryStart(image);
                }
                else
                {
                    animation.Cancel();
                }
            }

            LastSelectedItem = null;
        }
        private static void ExecutePreparedTransition(ITransitionMapper tm, Page pageFrom, Page pageTo, bool isPop)
        {
            var cas = ConnectedAnimationService.GetForCurrentView();

            var transFrom = (IReadOnlyList <TransitionDetail>)pageFrom?.GetValue(SharedTransitionNavigationPage.TransitionFromMapProperty);

            pageFrom?.SetValue(SharedTransitionNavigationPage.TransitionFromMapProperty, null);

            // group is used when popping back to a page with the group defined
            var group   = (string)pageTo?.GetValue(SharedTransitionNavigationPage.TransitionSelectedGroupProperty);
            var transTo = tm.GetMap(pageTo, group, !isPop);

            foreach (var detail in transTo)
            {
                ConnectedAnimation animation = cas.GetAnimation(detail.TransitionName);
                if (animation != null)
                {
                    if (detail.NativeView.IsAlive)
                    {
                        if (detail.View.Height == -1)
                        {
                            // need to capture the value and then use that in the event handler since it changes with each time through the loop
                            var acapture = animation;
                            detail.View.SizeChanged += (s, e) =>
                            {
                                // save this so we only call TryStart on the first time through
                                var atemp = acapture;
                                acapture = null;
                                if (atemp != null && detail.NativeView.IsAlive)
                                {
                                    atemp.TryStart((UIElement)detail.NativeView.Target);
                                }
                            };
                        }
                        else
                        {
                            var b = animation.TryStart((UIElement)detail.NativeView.Target);
                        }
                    }
                }
            }

            foreach (var transChk in transFrom ?? Enumerable.Empty <TransitionDetail>())
            {
                if (!transTo.Any(t => t.TransitionName == transChk.TransitionName))
                {
                    // transFrom item not in transTo
                    ConnectedAnimation animation = cas.GetAnimation(transChk.TransitionName);
                    if (animation != null)
                    {
                        animation.Cancel();
                    }

                    if (isPop)
                    {
                        // TODO: figure out why this is needed
                        transChk.View.IsVisible = false;
                        if (transChk.NativeView.IsAlive)
                        {
                            ((UIElement)transChk.NativeView.Target).Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
        }