Пример #1
0
        public void SetElement(VisualElement element)
        {
            var newPage = element as CarouselPage;

            if (element != null && newPage == null)
            {
                throw new ArgumentException("element must be a CarouselPage");
            }

            CarouselPage oldPage = Element;

            Element = newPage;

            if (oldPage != null)
            {
                oldPage.SendDisappearing();
                ((INotifyCollectionChanged)oldPage.Children).CollectionChanged -= OnChildrenChanged;
                oldPage.PropertyChanged -= OnElementPropertyChanged;
            }

            if (newPage != null)
            {
                if (_tracker == null)
                {
                    _tracker = new BackgroundTracker <FlipView>(BackgroundProperty)
                    {
                        Control = this, Container = this
                    };
                }

                _tracker.Element = newPage;

                // Adding Items triggers the SelectionChanged event,
                // which will reset the CurrentPage unless we tell it to ignore.
                _fromUpdate = true;
                for (var i = 0; i < newPage.Children.Count; i++)
                {
                    Items.Add(newPage.Children[i]);
                }
                _fromUpdate = false;

                ((INotifyCollectionChanged)newPage.Children).CollectionChanged += OnChildrenChanged;
                newPage.PropertyChanged += OnElementPropertyChanged;

                UpdateCurrentPage();
                newPage.SendAppearing();
            }

            OnElementChanged(new ElementChangedEventArgs <CarouselPage>(oldPage, newPage));

            if (!string.IsNullOrEmpty(Element?.AutomationId))
            {
                SetValue(Windows.UI.Xaml.Automation.AutomationProperties.AutomationIdProperty, Element.AutomationId);
            }
        }
Пример #2
0
        public void SetElement(VisualElement element)
        {
            CarouselPage oldElement = _page;

            _page    = (CarouselPage)element;
            _tracker = new BackgroundTracker <Control>(BackgroundProperty)
            {
                Model = _page, Element = this
            };

            DataContext = _page;

            SelectionChanged += OnSelectionChanged;

            OnPagesChanged(_page, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

            _page.PagesChanged    += OnPagesChanged;
            _page.PropertyChanged += OnPropertyChanged;

            Loaded   += (sender, args) => _page.SendAppearing();
            Unloaded += (sender, args) => _page.SendDisappearing();

            OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
        }