示例#1
0
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            // Code might use some null reference checks here.

            this.layoutRoot = this.GetTemplateChild(LayoutRootPartName) as Grid;

            this.selectRegion = this.GetTemplateChild(SelectRegionPartName) as Path;
            this.selectRegion.ManipulationMode = ManipulationModes.Scale | ManipulationModes.TranslateX | ManipulationModes.TranslateY;
            selectedRegion = new SelectedRegion {
                MinSelectRegionSize = 2 * CornerSize
            };
            this.DataContext = selectedRegion;

            this.topLeftCorner     = this.GetTemplateChild(TopLeftCornerPartName) as ContentControl;
            this.topRightCorner    = this.GetTemplateChild(TopRightCornerPartName) as ContentControl;
            this.bottomLeftCorner  = this.GetTemplateChild(BottomLeftCornerPartName) as ContentControl;
            this.bottomRightCorner = this.GetTemplateChild(BottomRightCornerPartName) as ContentControl;

            this.imageCanvas = this.GetTemplateChild(ImageCanvasPartName) as Canvas;
            this.sourceImage = this.GetTemplateChild(SourceImagePartName) as Image;

            // Handle the pointer events of the corners.
            AddCornerEvents(this.topLeftCorner);
            AddCornerEvents(this.topRightCorner);
            AddCornerEvents(this.bottomLeftCorner);
            AddCornerEvents(this.bottomRightCorner);

            // Handle the manipulation events of the selectRegion
            this.selectRegion.ManipulationDelta     += SelectRegion_ManipulationDelta;
            this.selectRegion.ManipulationCompleted += SelectRegion_ManipulationCompleted;

            this.sourceImage.SizeChanged += SourceImage_SizeChanged;
        }
        /// <summary>
        /// Template to manage crop selection of image.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _layoutRoot = GetTemplateChild("PART_LayoutRoot") as Grid;

            _selectRegion = GetTemplateChild("PART_SelectRegion") as Path;
            _selectRegion.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
            _selectedRegion = new SelectedRegion {
                MinSelectRegionSize = AppEnvironment.DefaultMinimumCropDimension
            };
            DataContext = _selectedRegion;

            _sourceImage = GetTemplateChild("PART_SourceImage") as Image;
            _imageCanvas = GetTemplateChild("PART_ImageCanvas") as Canvas;

            _topLeftCorner     = GetTemplateChild("PART_TopLeftCorner") as ContentControl;
            _topRightCorner    = GetTemplateChild("PART_TopRightCorner") as ContentControl;
            _bottomLeftCorner  = GetTemplateChild("PART_BottomLeftCorner") as ContentControl;
            _bottomRightCorner = GetTemplateChild("PART_BottomRightCorner") as ContentControl;

            // Handle the pointer events of the corners.
            AddCornerEvents(_topLeftCorner);
            AddCornerEvents(_topRightCorner);
            AddCornerEvents(_bottomLeftCorner);
            AddCornerEvents(_bottomRightCorner);

            // Handle the manipulation events of the selectRegion
            _selectRegion.ManipulationDelta     += SelectRegion_ManipulationDelta;
            _selectRegion.ManipulationCompleted += SelectRegion_ManipulationCompleted;

            _sourceImage.SizeChanged += sourceImage_SizeChanged;
        }