Beispiel #1
0
        protected override void OnAttachedTo(VisualElement visualElement)
        {
            // Set the previous display
            currentInfo = new DisplayViewInfo
            {
                DisplayInfo = DeviceDisplay.MainDisplayInfo,
                PageHeight  = 0,
                PageWidth   = 0
            };

            // Size changed handler
            var sizeChangedSubscription = Observable.FromEventPattern(
                evt => visualElement.SizeChanged += evt,
                evt => visualElement.SizeChanged -= evt
                )
                                          .Sample(TimeSpan.FromMilliseconds(1000))
                                          .Select(o => new Tuple <double, double>(visualElement.Width, visualElement.Height))
                                          .Where(t => t.Item1 > 0 && t.Item2 > 0)
                                          //.DistinctUntilChanged()
                                          .ObserveOn(SynchronizationContext.Current)
                                          .Subscribe(value =>
            {
                var(item1, item2)      = value;
                currentInfo.PageWidth  = item1;
                currentInfo.PageHeight = item2;

                OnInfoChanged();
            }
                                                     );

            ;

            disposables.Add(sizeChangedSubscription);

            // Orientation changed handler
            var displaySubscription = Observable.FromEventPattern <DisplayInfoChangedEventArgs>(
                evt => DeviceDisplay.MainDisplayInfoChanged += evt,
                evt => DeviceDisplay.MainDisplayInfoChanged -= evt
                )
                                      .Select(x => x.EventArgs.DisplayInfo)
                                      .DistinctUntilChanged(this.DisplayInfoComparer)
                                      .Subscribe(info =>
            {
                currentInfo.DisplayInfo = info;
                OnInfoChanged();
            })
            ;

            disposables.Add(displaySubscription);

            base.OnAttachedTo(visualElement);
        }
        public IconSizeCalculator(int itemsPerRow)
        {
            // We need this to get the current orientation in GetItemsPerRowDefault()
            this.displayViewInfo = new DisplayViewInfo()
            {
                DisplayInfo = DeviceDisplay.MainDisplayInfo
            };

            this.itemInfo = new ListViewItemInfo
            {
                ItemsPerRow = itemsPerRow > 0 ? itemsPerRow : GetItemsPerRowDefault()
            };

            this.ScaleFactor = 0.6;
        }
 public void ChangeDisplayViewInfo(DisplayViewInfo info)
 {
     this.displayViewInfo = info;
     this.OnItemInfoChanged();
 }