示例#1
0
        public async void OnSelectionChanged(InkCanvasSelectionChangingEventArgs args)
        {
            if (IsSelectionDifferent(args.GetSelectedStrokes()))
            {
                // We make the previously selected strokes unselected
                var strokesToUpdate = new Dictionary <string, string>();
                DrawingModel?.SelectedStrokes?.Where(x => x.Value == UserId).ForEach(x => strokesToUpdate[x.Key] = null);

                // We make the currently selected strokes selected
                var selectedStrokes = new List <StrokeModel>();
                foreach (var s in args.GetSelectedStrokes())
                {
                    var stroke = s as StrokeModel;
                    if (stroke == null || IsSelectedByOtherUser(stroke))
                    {
                        continue;
                    }
                    selectedStrokes.Add(stroke as StrokeModel);
                }

                SelectedStrokesIds = new HashSet <string>(selectedStrokes.Select(x => x.Id));
                SelectedStrokesIds.ForEach(x => strokesToUpdate[x] = UserId);

                SelectionChanged?.Invoke(SelectedStrokes);
                args.SetSelectedStrokes(new StrokeCollection(SelectedStrokes));

                if (!IsOffline)
                {
                    await DatabaseService.Ref(DatabasePaths.Drawings)
                    .Child(Id)
                    .Child(DatabasePaths.SelectedStrokes)
                    .Update(strokesToUpdate);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Prevent user from selecting eraser strokes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void selectionChanging(object sender, InkCanvasSelectionChangingEventArgs e)
        {
            StrokeCollection selectedStrokes         = e.GetSelectedStrokes();
            StrokeCollection actuallySelectedStrokes = new StrokeCollection();

            foreach (Stroke stroke in selectedStrokes)
            {
                if (stroke.DrawingAttributes.Color != Color.FromRgb(255, 255, 255))
                {
                    actuallySelectedStrokes.Add(stroke);
                }
            }
            e.SetSelectedStrokes(actuallySelectedStrokes);
        }
示例#3
0
        /// <summary>
        /// OnSelectionChanging raised when selection is changing on the InkAnalysisCanvas
        /// we use this to select entire nodes instead of just a stroke
        /// </summary>
        protected override void OnSelectionChanging(InkCanvasSelectionChangingEventArgs e)
        {
            StrokeCollection currentSelectedStrokes = e.GetSelectedStrokes();

            if (currentSelectedStrokes.Count > 0)
            {
                ContextNodeCollection nodes =
                    _inkAnalyzer.FindInkLeafNodes(e.GetSelectedStrokes());

                if (nodes.Count > 0)
                {
                    StrokeCollection expandedSelection = new StrokeCollection();
                    //add all related strokes if they aren't part of selectedStrokes already
                    foreach (ContextNode node in nodes)
                    {
                        expandedSelection.Add(node.Strokes);
                    }
                    //modify the collection
                    e.SetSelectedStrokes(expandedSelection);
                }
            }

            base.OnSelectionChanging(e);
        }