Draw line

Hi Walter. I have a question. Now GoDiagram draw lines between 2 Nodes.
From one node to second node. Can I draw line on canvas diagram simply set coordinate from x1, y1 to x2, y2.
Without linking them to the shapes ?

Thanks.

<DataTemplate x:Key="ArbitraryLine"> <font color="#ff0000">[Edit: this has been replaced by a better definition in a reply below]</font> <Path Stroke="Black" StrokeThickness="3" go:Part.SelectionAdorned="True" go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"> <Path.Data> <!-- this databinding works only in Silverlight 4 or WPF --> <LineGeometry StartPoint="{Binding Path=Data.Start}" EndPoint="{Binding Path=Data.End}" /> </Path.Data> </Path> </DataTemplate>
and:

[code] public class ArbitraryLine : GraphModelNodeData {
public Point Start {
get { return _Start; }
set {
if (_Start != value) {
Point old = _Start;
_Start = value;
RaisePropertyChanged(“Start”, old, value);
}
}
}
private Point _Start;

public Point End {
  get { return _End; }
  set {
    if (_End != value) {
      Point old = _End;
      _End = value;
      RaisePropertyChanged("End", old, value);
    }
  }
}
private Point _End = new Point(100, 100);

}[/code]

The above XAML and code work just fine in WPF. Please note that the StartPoint and EndPoint are relative to the Location of the Node – they are not absolute model coordinates.

If you are using Silverlight, you’ll note that the Binding in the LineGeometry can only be done in Silverlight 4, not in Silverlight 3.

Furthermore, only in Silverlight, there appears to be some kind of bug in the picking of such lines. We’re investigating this right now. [Edit: See the reply below.]

Walter, thanks for speedly response.

One of us has discovered that wrapping the Path in a NodePanel or Border seems to fix all of the selection problems.

Here’s the updated XAML:

<DataTemplate x:Key="ArbitraryLine"> <Border go:Part.SelectionElementName="Shape" go:Part.SelectionAdorned="True" go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"> <Path x:Name="Shape" Stroke="Black" StrokeThickness="3"> <Path.Data> <!-- this databinding works only in Silverlight 4 or WPF --> <LineGeometry StartPoint="{Binding Path=Data.Start}" EndPoint="{Binding Path=Data.End}" /> </Path.Data> </Path> </Border> </DataTemplate>
This works well in either Silverlight 4 or WPF.

Could I simply add a Line to a Layer without using DataTemplate?

Thanks!

To be in a NodeLayer, it has to be a Node.

If you don’t want to use a DataTemplate, that means you don’t want to use data-binding. That’s OK – read the section in the GoXamIntro about “Decorative Elements and Unbound Parts”. But there are restrictions on what you can do with such nodes. They include no copying and no links to/from data-bound nodes.

Good day. I did have the unbound line as you advised. But I have small aesthetics problem. When I drag the end or start point of the line to new location , the “select” rectangle appear. Is there any way to remove or hide it ?

The DragSelectingTool starts when the user does a mouse-down and drag when there are no objects at the mouse-down point.

If you don’t want to allow users to select multiple objects within a drawn rectangle, you can remove the tool by setting Diagram.DragSelectingTool to null. Either:
myDiagram.DragSelectingTool = null;
or:
<go:Diagram … DragSelectingTool="{x:Null}">

I am able to switch from selecting multiple nodes in the rectangle to dragging the diagram by setting
Diagram.DragSelectingTool to null, but how would i switch back?
i have tried setting it to a new DragSelectingTool with no luck:



If Me.myDiagram.DragSelectingTool IsNot Nothing Then
Me.myDiagram.DragSelectingTool = Nothing
Else
Me.myDiagram.DragSelectingTool = New Northwoods.GoXam.Tool.DragSelectingTool
End If

I have also tried setting it to what it was previously:

<span =“Apple-tab-span” style=“white-space:pre”> Private DraggingTool As Northwoods.GoXam.Tool.DragSelectingTool

<span =“Apple-tab-span” style=“white-space:pre”> DraggingTool = Me.myDiagram.DragSelectingTool

    If Me.myDiagram.DragSelectingTool IsNot Nothing Then
      Me.myDiagram.DragSelectingTool = Nothing
    Else
      Me.myDiagram.DragSelectingTool = DraggingTool 
    End If

Please let me know how i could achieve this.
thanks in advance!

It might easier to set …Tool.MouseEnabled to false or true, as desired, in your mode-switching command.