/// <summary>
        /// Updates selected elements according to rubberband adorner position
        /// </summary>
        private void UpdateSelection()
        {
            this.Rectangle = new Rect(this.startPoint.Value, this.endPoint.Value);

            // update selection only when in appropriate mode
            if (!this.toSelect)
            {
                return;
            }

            this.canvas.ClearSelection();

            foreach (ContentPresenter presenter in this.canvas.Children)
            {
                // get item bounds
                Rect itemRect   = VisualTreeHelper.GetDescendantBounds(presenter);
                Rect itemBounds = presenter.TransformToAncestor(this.canvas).TransformBounds(itemRect);

                // check if item contains in rubberband rectangle
                if (this.Rectangle.IntersectsWith(itemBounds))
                {
                    // select item
                    BaseOmrElement question = (BaseOmrElement)VisualTreeHelper.GetChild(presenter, 0);
                    question.IsSelected = true;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds all selected base omr elements inside canvas
        /// </summary>
        /// <param name="canvas">Canvas containing searched items</param>
        /// <returns>List of content presenters with selected items</returns>
        public static List <ContentPresenter> GetSelectedChildPresenters(CustomCanvas canvas)
        {
            List <ContentPresenter> presenters = new List <ContentPresenter>();
            int childsCount = VisualTreeHelper.GetChildrenCount(canvas);

            for (int i = 0; i < childsCount; i++)
            {
                ContentPresenter childPresenter = (ContentPresenter)VisualTreeHelper.GetChild(canvas, i);
                BaseOmrElement   childOmrItem   = (BaseOmrElement)VisualTreeHelper.GetChild(childPresenter, 0);

                if (childOmrItem.IsSelected)
                {
                    presenters.Add(childPresenter);
                }
            }

            return(presenters);
        }
        /// <summary>
        /// Clears elements selection
        /// </summary>
        public void ClearSelection()
        {
            // find all content presenters wrapping child items (questions or bubbles)
            List <ContentPresenter> presenters = ControlHelper.GetChildPresenters(this);

            foreach (ContentPresenter presenter in presenters)
            {
                // find actual omr element that wrapped inside presenter
                BaseOmrElement omrElement = VisualTreeHelper.GetChild(presenter, 0) as BaseOmrElement;

                if (omrElement != null)
                {
                    if (omrElement.IsSelected)
                    {
                        omrElement.IsSelected = false;
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fires on IsSelected property changed
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The event args</param>
        private static void IsSelectedPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            BaseOmrElement question = (BaseOmrElement)sender;

            question.UpdateAdorners((bool)e.NewValue);
        }