Inheritance: Windows.UI.Xaml.Controls.UserControl
示例#1
0
        /*public List<Control> AllChildren(DependencyObject parent)
         * {
         *  var _list = new List<Control>();
         *  for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
         *  {
         *      var _child = VisualTreeHelper.GetChild(parent, i);
         *      if (_child is Control)
         *          _list.Add(_child as Control);
         *      _list.AddRange(AllChildren(_child));
         *  }
         *  return _list;
         * }*/

        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                indicators = null;

                if (flipView != null)
                {
                    flipView.SelectionChanged -= FlipView_SelectionChanged;
                    flipView = null;
                }

                if (Element != null)
                {
                    if (Element.ItemsSource != null && Element.ItemsSource is INotifyCollectionChanged)
                    {
                        ((INotifyCollectionChanged)Element.ItemsSource).CollectionChanged -= ItemsSource_CollectionChanged;
                    }
                }

                nativeView = null;

                _disposed = true;
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (Exception ex)
            {
                return;
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                prevBtn = null;
                nextBtn = null;

                indicators = null;

                if (flipView != null)
                {
                    flipView.SelectionChanged -= FlipView_SelectionChanged;
                    flipView = null;
                }

                if (_collectionListenerSource != null)
                {
                    _collectionListenerSource.CollectionChanged -= ItemsSource_CollectionChanged;
                    _collectionListenerSource = null;
                }

                nativeView = null;

                _disposed = true;
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (Exception ex)
            {
                return;
            }
        }
示例#3
0
        public void SetNativeView()
        {
            var position = Element.Position;

            if (nativeView == null)
            {
                nativeView = new FlipViewControl(Element.IsSwipingEnabled);
                flipView   = nativeView.FindName("flipView") as FlipView;
            }

            if (orientationChanged)
            {
                // Orientation BP
                if (Element.Orientation == CarouselViewOrientation.Horizontal)
                {
                    flipView.ItemsPanel = nativeView.Resources["HPanel"] as ItemsPanelTemplate;
                }
                else
                {
                    flipView.ItemsPanel = nativeView.Resources["VPanel"] as ItemsPanelTemplate;
                }

                orientationChanged = false;
            }

            var source = new List <FrameworkElement>();

            if (Element.ItemsSource != null && Element.ItemsSource?.GetCount() > 0)
            {
                for (int j = 0; j <= Element.ItemsSource.GetCount() - 1; j++)
                {
                    source.Add(CreateView(Element.ItemsSource.GetItem(j)));
                }
            }

            Source = new ObservableCollection <FrameworkElement>(source);
            flipView.ItemsSource = Source;

            //flipView.ItemsSource = Element.ItemsSource;
            //flipView.ItemTemplateSelector = new MyTemplateSelector(Element); (the way it should be)

            converter = new ColorConverter();

            // BackgroundColor BP
            flipView.Background = (SolidColorBrush)converter.Convert(Element.BackgroundColor, null, null, null);

            // IndicatorsTintColor BP
            fillColor = (SolidColorBrush)converter.Convert(Element.IndicatorsTintColor, null, null, null);

            // CurrentPageIndicatorTintColor BP
            selectedColor = (SolidColorBrush)converter.Convert(Element.CurrentPageIndicatorTintColor, null, null, null);

            flipView.Loaded           += FlipView_Loaded;
            flipView.SelectionChanged += FlipView_SelectionChanged;
            flipView.SizeChanged      += FlipView_SizeChanged;

            //IsSwipingEnabled BP (not working)
            //flipView.ManipulationMode = Element.IsSwipingEnabled ? ManipulationModes.All : ManipulationModes.None;

            if (Source.Count > 0)
            {
                flipView.SelectedIndex = position;
            }

            SetNativeControl(nativeView);

            // INDICATORS
            indicators = nativeView.FindName("indicators") as StackPanel;
            SetIndicators();
        }