IsSelected

Hello,

I use WPf last version.

Suppose you have 2 nodes. n1 is selected.
Can you explain me the mechanism that allows to set n1.IsSelected to false, when we click on n2 ?

In one case, when i perform paste, n1 is selected, but when I click on n2, n1 is not deselected. I should click in the diagram background after to deselect the both. And then selection works well.

I have binded the Part.IsSelected property with one of my model property.
At the end of CommandHandler.Paste, the IsSelected property is well defined, as my model property.

public override void Paste()
        {
            Diagram diagram = this.Diagram;
            if (diagram == null) return;
           
            Session.AppContext.CurrentEnvironment.Paste(null);

        /* ====== we don't need this, it was just a try ====*/
            QDiagramEnvironment DataContextDiagram = Session.AppContext.CurrentEnvironment as QDiagramEnvironment;

            foreach (SphItem oItem in DataContextDiagram.SelectedItems)
            {
                QD_Node oNode = DataContextDiagram.QD_Model.FindNodeByKey(oItem.ID.ToString());
                if (oNode == null) return;
                Node oPart =  this.Diagram.PartManager.FindNodeForData(oNode, DataContextDiagram.QD_Model);
                if (oPart == null) return;
                oPart.IsSelected = true;
            }
     /*=============*/
        }

As you can see in the code, i don’t use the clipboard mechanism, but override all the copy/paste functions in my own commandhandler.

Where’s my mistake ?

Thanks
Aurore

Are you using a Mode=TwoWay data-binding of Part.IsSelected?

It isn’t clear to me that it’s possible to data-bind Part.IsSelected and keep the standard selection behavior.

yes, it is in twoway mode

 protected override Node MakeNodeForData(object nodedata, IDiagramModel model, bool isgroup, bool islinklabel, string category, DataTemplate templ)
        {
            Node oNode = base.MakeNodeForData(nodedata, model, isgroup, islinklabel, category, templ);
            if (oNode != null)
            {
               
                    Binding binding = new Binding()
                    {
                        Path = new PropertyPath("Data.Item.ExtendedProperties[IsQDSelected]"),
                        Converter = (IValueConverter)this.TryFindResource("convObjectBoolean"),
                        Mode = BindingMode.TwoWay
                    };
                    oNode.SetBinding(Part.IsSelectedProperty, binding);
                }
            
            return oNode;
        }    

DiagramTool.StandardMouseSelect is the implementation of the standard selection behavior when there are mouse clicks.

When the user clicks on a Part that is not IsSelected, it calls Diagram.Select on that part.

Diagram.Select is defined as:
public void Select(Part part) {
VerifyAccess();
if (part != null && part.Diagram == this) {
if (!part.IsSelected || this.SelectedParts.Count > 1) {
ClearSelection();
part.IsSelected = true;
}
}
}

Diagram.ClearSelection is defined as:
public void ClearSelection() {
VerifyAccess();
ObservableCollection sel = this.SelectedParts;
if (sel.Count > 0) sel.Clear();
this.SelectedPart = null;
this.SelectedNode = null;
this.SelectedGroup = null;
this.SelectedLink = null;
}

I don’t understand…
I tried to make a smaller sample that reproduces the trick but i can’t.

But in my project I got this situation :

the Diagram.Part.IsSelected is true, but SelectedParts, SelectedNode et SelectedPart are empty !!

Aurore

I still think you are going about this the wrong way.

What is it you really want to achieve?
Then we can figure out how to implement it.