예제 #1
0
 private void DetachFromVisualTree()
 {
     // remove the view finder display panel's visual brush and adorner
     _viewFinderDisplay = null;
 }
예제 #2
0
        private void AttachToVisualTree()
        {
            // detach from the old tree
            DetachFromVisualTree();
            // set a reference to the ViewFinder element, if present
            SetValue(ViewFinderPropertyKey, Template.FindName("ViewFinder", this) as FrameworkElement);

            // locate the view finder display panel
            _viewFinderDisplay = VisualTreeHelperEx.FindDescendantByType(this, typeof(ViewFinderDisplay)) as ViewFinderDisplay;

            // if a ViewFinder was specified but no display panel is present, throw an exception
            if (ViewFinder != null && _viewFinderDisplay == null)
                throw new Exception("ZoomControlHasViewFinderButNotDisplay");

            // set up the VisualBrush and adorner for the display panel
            if (_viewFinderDisplay != null)
            {
                // create VisualBrush for the view finder display panel
                CreateVisualBrushForViewFinder(Content as Visual);
                _viewFinderDisplay.Background = this.Background;

                // hook up event handlers for dragging and resizing the viewport
                _viewFinderDisplay.MouseMove += ViewFinderDisplayMouseMove;
                _viewFinderDisplay.MouseLeftButtonDown += ViewFinderDisplayBeginCapture;
                _viewFinderDisplay.MouseLeftButtonUp += ViewFinderDisplayEndCapture;
            }
        }