コード例 #1
0
        protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);

            //Set all defaults for Trip views
            _trips = new List <TripOffset>()
            {
                new TripOffset {
                    Trip = view1, TripBackgroundImage = view0Image, Offset = 0
                },
                new TripOffset {
                    Trip = view2, TripBackgroundImage = view2Image, Offset = width
                },
                new TripOffset {
                    Trip = view3, TripBackgroundImage = view3Image, Offset = width * 2
                }
            };
            _currentTrip = _trips[0];
            view1.CalculateOffsets(0, width, 0, false);
            bgImage0.Opacity = 1;
            view2.CalculateOffsets(width, width, width, false);
            bgImage2.Opacity = 1;
            view3.CalculateOffsets(width * 2, width, width * 2, false);
            bgImage3.Opacity = 1;
        }
コード例 #2
0
        public void PanCompleted(object sender, PanEventArgs panEventArgs)
        {
            whiteoverlay.Opacity = .5;

            scrollingContainer.IsEnabled = true;
            disabled = false;
            counter  = 0;

            if (panEventArgs.Cancelled)
            {
                foreach (var trip in _trips)
                {
                    trip.Trip.CalculateOffsets(trip.Offset, scrollingContainer.Width, trip.Offset, false);
                }
            }

            var container = sender as View;

            var snapFromDistance = (Math.Abs(_lastX) + 20) > (container.Width / 2);
            var snapFromSpeed    = Math.Abs(panEventArgs.Velocity.X) > 800;

            if (snapFromSpeed || snapFromDistance)
            {
                if (_lastX > 0) //show the one to the left
                {
                    if (_trips[0] != _currentTrip)
                    {
                        foreach (var trip in _trips)
                        {
                            trip.Offset = trip.Offset + container.Width;
                        }
                    }
                }
                else
                {
                    if (_trips[_trips.Count - 1] != _currentTrip)
                    {
                        foreach (var trip in _trips)
                        {
                            trip.Offset = trip.Offset - container.Width;
                        }
                    }
                }
            }

            //Go through the trips and move into default positions.
            foreach (var trip in _trips)
            {
                if (trip.Offset == 0)
                {
                    _currentTrip = trip;
                    trip.TripBackgroundImage.Opacity = 1;
                }
                else
                {
                    trip.TripBackgroundImage.Opacity = 0;
                }

                trip.Trip.CalculateOffsets(trip.Offset, scrollingContainer.Width, trip.Offset, true);
            }
        }