This is a migrated thread and some comments may be shown as answers.

How to avoid select single item of group

2 Answers 151 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Dario Concilio
Top achievements
Rank 2
Dario Concilio asked on 23 Jun 2017, 12:27 PM

Hi to all,

I would avoid that user click single item of group.

Sequence to reproduce behaviour:

  1. Group more items
  2. Unselect group
  3. Click on group and group id selected
  4. Click again on single item (of group) and selected item is only item that I clicked.

I would that step no. 4 did not have any effect.

To highlight selected items, I have write code into SelectionChanged event, where I change background and foreground of selected item.

01.private void topRadDiagram_SelectionChanged(object sender, SelectionChangedEventArgs e)
02.{
03.    //Deselezione degli oggetti
04.    foreach (var item in e.RemovedItems)
05.    {
06.        if (item is RadDiagramShape deselectedItem)
07.        {
08.            deselectedItem.Background = ColorHelper.IMBALLO;
09.            deselectedItem.Foreground = ColorHelper.IMBALLO_TITLE;
10. 
11.            //Aggiorna il 3D
12.            var macchina = (ModelloCommerciale)deselectedItem.Tag;
13.            var macchina3D = macchina.Oggetto3D;
14.            macchina3D.Material = new DiffuseMaterial(ColorHelper.IMBALLO_TRASPARENTE);
15.            macchina3D.BackMaterial = new DiffuseMaterial(ColorHelper.IMBALLO_TRASPARENTE);
16.        }
17.    }
18. 
19.    //Selezione degli oggetti
20.    foreach (var item in e.AddedItems)
21.    {
22.        if (item is RadDiagramShape selectedItem)
23.        {
24.            selectedItem.Background = ColorHelper.IMBALLO_SELEZIONATO;
25.            selectedItem.Foreground = ColorHelper.IMBALLO_TITLE_SELEZIONATO;
26. 
27.            //Aggiorna il 3D
28.            var macchina = (ModelloCommerciale)selectedItem.Tag;
29.            var macchina3D = macchina.Oggetto3D;
30.            macchina3D.Material = new DiffuseMaterial(ColorHelper.IMBALLO_SELEZIONATO);
31.            macchina3D.BackMaterial = new DiffuseMaterial(ColorHelper.IMBALLO_SELEZIONATO);
32. 
33.            //Gesione trasparenza, è necessario per poter vedere trasparenti gli altri oggetti 3D
34.            //bisogna portare da index = 0 gli oggetti selezionati
35. 
36.            //Rimuovo l'oggetto 3D attuale
37.            this.oggettiModel3DGroup.Children.Remove(macchina3D);
38.            //Reinserisco l'oggetto 3D con index = 0
39.            this.oggettiModel3DGroup.Children.Insert(0, macchina3D);
40.        }
41.    }

2 Answers, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 28 Jun 2017, 11:25 AM
Hello Dario,

Thank you for contacting us.

Let me start with that the RadDiagram doesn't support disabling this functionality out of the box. You can achieve such behavior by implementing custom code. Basically, you can subscribe to the PreviewSelectionChanged event of the diagram and check if you are selecting an item and if the selected item has a group.

For your convenience, we have created sample project which demonstrates this approach. Keep in mind that this custom code is not fully tested and there could be cases where this code would not work as expected but you can modify to fit in your scenario.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Dario Concilio
Top achievements
Rank 2
answered on 29 Jun 2017, 08:20 AM

Ok I understood,

Thank you Dinko.

My final code.

01.if (e.AddedItems.Count > 0)
02.{
03.    foreach (var selectedItem in e.AddedItems)
04.    {
05.        if (selectedItem.GetType() == typeof(RadDiagramShape))
06.        {
07.            var shape = (RadDiagramShape)selectedItem;
08. 
09.            if (shape.ParentGroup != null)
10.            {
11.                var group = shape.ParentGroup;
12. 
13.                if (e.RemovedItems.Count > 1)
14.                {
15.                    e.Handled = true;
16.                }
17.            }
18.        }
19.    }
20.}
Tags
Diagram
Asked by
Dario Concilio
Top achievements
Rank 2
Answers by
Dinko | Tech Support Engineer
Telerik team
Dario Concilio
Top achievements
Rank 2
Share this question
or