protected override void OnApplyTemplate() { base.OnApplyTemplate(); // Get the original elements from the template _rootGrid = this.GetTemplateChild("RootGrid") as Panel; _canvas = this.GetTemplateChild("canvas") as Panel; var indiRect = this.GetTemplateChild("indicatorRect") as Rectangle; _indicatorVisual = ElementCompositionPreview.GetElementVisual(indiRect); _touchAreaVisual = ElementCompositionPreview.GetElementVisual(_canvas); _compositor = _touchAreaVisual.Compositor; _itemVisualList = new List <Visual>(); _itemUIElementList = _canvas.GetDescendantsOfType <CarouselViewItem>().ToList(); foreach (var item in _itemUIElementList) { _itemVisualList.Add(ElementCompositionPreview.GetElementVisual(item)); } // Event handlers this._canvas.ManipulationMode = ManipulationModes.TranslateX; _canvas.ManipulationStarted += Canvas_ManipulationStarted; _canvas.ManipulationDelta += Canvas_ManipulationDelta; _canvas.ManipulationCompleted += Canvas_ManipulationCompleted; //_canvas.ManipulationInertiaStarting += Canvas_ManipulationInertiaStarting; _canvas.PointerWheelChanged += Canvas_PointerWheelChanged; // Response to the SizeChanged _rootGrid.SizeChanged += (ss, ee) => { MeasureItemsPosition(_selectedIndex); // Change the Clip to fit new size _canvas.Clip = new RectangleGeometry() { Rect = RectHelper.FromCoordinatesAndDimensions(0, 0, (float)ee.NewSize.Width, (float)ee.NewSize.Height) }; }; //_canvas.SizeChanged += (ss, ee) => { MeasureItemsPosition(_selectedIndex, _selectedIndex); }; this.Loaded += (ss, ee) => { // Initial items' image data SetItemsImageSource(true); SetSelectedAppearance(); //MeasureItemsPosition(_selectedIndex); }; }