@@ -76,14 +76,14 @@ private void OnItemsSelectStarted()
7676 ItemsSelectStartedCommand . Execute ( DataContext ) ;
7777 }
7878
79- /// <summary>Invoked when a selection operation is started.</summary>
79+ /// <summary>Invoked when a selection operation is started (see <see cref="BeginSelecting(SelectionType)"/>) .</summary>
8080 public ICommand ? ItemsSelectStartedCommand
8181 {
8282 get => ( ICommand ? ) GetValue ( ItemsSelectStartedCommandProperty ) ;
8383 set => SetValue ( ItemsSelectStartedCommandProperty , value ) ;
8484 }
8585
86- /// <summary>Invoked when a selection operation is completed.</summary>
86+ /// <summary>Invoked when a selection operation is completed (see <see cref="EndSelecting"/>) .</summary>
8787 public ICommand ? ItemsSelectCompletedCommand
8888 {
8989 get => ( ICommand ? ) GetValue ( ItemsSelectCompletedCommandProperty ) ;
@@ -216,42 +216,6 @@ protected internal IReadOnlyList<ItemContainer> SelectedContainers
216216
217217 #region Selection
218218
219- internal void ApplyPreviewingSelection ( )
220- {
221- Debug . Assert ( IsSelecting ) ;
222-
223- ItemCollection items = Items ;
224- IList selected = base . SelectedItems ;
225-
226- BeginUpdateSelectedItems ( ) ;
227- for ( var i = 0 ; i < items . Count ; i ++ )
228- {
229- var container = ( ItemContainer ) ItemContainerGenerator . ContainerFromIndex ( i ) ;
230- if ( container . IsPreviewingSelection == true && container . IsSelectable )
231- {
232- selected . Add ( items [ i ] ) ;
233- }
234- else if ( container . IsPreviewingSelection == false )
235- {
236- selected . Remove ( items [ i ] ) ;
237- }
238- container . IsPreviewingSelection = null ;
239- }
240- EndUpdateSelectedItems ( ) ;
241- }
242-
243- internal void ClearPreviewingSelection ( )
244- {
245- Debug . Assert ( IsSelecting ) ;
246-
247- ItemCollection items = Items ;
248- for ( var i = 0 ; i < items . Count ; i ++ )
249- {
250- var container = ( ItemContainer ) ItemContainerGenerator . ContainerFromIndex ( i ) ;
251- container . IsPreviewingSelection = null ;
252- }
253- }
254-
255219 /// <summary>
256220 /// Inverts the <see cref="ItemContainer"/>s selection in the specified <paramref name="area"/>.
257221 /// </summary>
@@ -293,16 +257,16 @@ public void InvertSelection(Rect area, bool fit = false)
293257 /// <param name="fit">True to check if the <paramref name="area"/> contains the <see cref="ItemContainer"/>. <br />False to check if <paramref name="area"/> intersects the <see cref="ItemContainer"/>.</param>
294258 public void SelectArea ( Rect area , bool append = false , bool fit = false )
295259 {
260+ IsSelecting = true ;
261+ BeginUpdateSelectedItems ( ) ;
262+
263+ IList selected = base . SelectedItems ;
296264 if ( ! append )
297265 {
298- UnselectAll ( ) ;
266+ selected . Clear ( ) ;
299267 }
300268
301269 ItemCollection items = Items ;
302- IList selected = base . SelectedItems ;
303-
304- IsSelecting = true ;
305- BeginUpdateSelectedItems ( ) ;
306270 for ( var i = 0 ; i < items . Count ; i ++ )
307271 {
308272 var container = ( ItemContainer ) ItemContainerGenerator . ContainerFromIndex ( i ) ;
@@ -311,10 +275,24 @@ public void SelectArea(Rect area, bool append = false, bool fit = false)
311275 selected . Add ( items [ i ] ) ;
312276 }
313277 }
278+
314279 EndUpdateSelectedItems ( ) ;
315280 IsSelecting = false ;
316281 }
317282
283+ /// <summary>
284+ /// Clears the current selection and selects the specified <see cref="ItemContainer"/> within the same selection transaction.
285+ /// </summary>
286+ /// <param name="container"></param>
287+ public void Select ( ItemContainer container )
288+ {
289+ BeginUpdateSelectedItems ( ) ;
290+ var selected = base . SelectedItems ;
291+ selected . Clear ( ) ;
292+ selected . Add ( container . DataContext ) ;
293+ EndUpdateSelectedItems ( ) ;
294+ }
295+
318296 /// <summary>
319297 /// Unselect the <see cref="ItemContainer"/>s in the specified <paramref name="area"/>.
320298 /// </summary>
@@ -359,6 +337,7 @@ public void SelectAllConnections()
359337 selector . SelectAll ( ) ;
360338 }
361339 }
340+
362341 /// <summary>
363342 /// Initiates a selection operation from the specified location.
364343 /// </summary>
@@ -420,7 +399,7 @@ public void EndSelecting()
420399 /// <remarks>This method has no effect if there's no selection operation in progress.</remarks>
421400 public void CancelSelecting ( )
422401 {
423- if ( ! AllowSelectionCancellation )
402+ if ( ! AllowSelectionCancellation )
424403 {
425404 EndSelecting ( ) ;
426405 return ;
@@ -433,6 +412,38 @@ public void CancelSelecting()
433412 }
434413 }
435414
415+ private void ApplyPreviewingSelection ( )
416+ {
417+ ItemCollection items = Items ;
418+ IList selected = base . SelectedItems ;
419+
420+ BeginUpdateSelectedItems ( ) ;
421+ for ( var i = 0 ; i < items . Count ; i ++ )
422+ {
423+ var container = ( ItemContainer ) ItemContainerGenerator . ContainerFromIndex ( i ) ;
424+ if ( container . IsPreviewingSelection == true && container . IsSelectable )
425+ {
426+ selected . Add ( items [ i ] ) ;
427+ }
428+ else if ( container . IsPreviewingSelection == false )
429+ {
430+ selected . Remove ( items [ i ] ) ;
431+ }
432+ container . IsPreviewingSelection = null ;
433+ }
434+ EndUpdateSelectedItems ( ) ;
435+ }
436+
437+ private void ClearPreviewingSelection ( )
438+ {
439+ ItemCollection items = Items ;
440+ for ( var i = 0 ; i < items . Count ; i ++ )
441+ {
442+ var container = ( ItemContainer ) ItemContainerGenerator . ContainerFromIndex ( i ) ;
443+ container . IsPreviewingSelection = null ;
444+ }
445+ }
446+
436447 #endregion
437448
438449 #region Selection Handlers
0 commit comments