Palette drag-and-drop issue

I am trying to use the Palette control, but I am not successful…

Below is my XAML and Code-behind.


<FrameworkElement.Resources>
<go:DataTemplateDictionary x:Key=“TemplateDictionary”>

<go:NodePanel
Width=“20” Height=“20”
Sizing=“Fixed”
go:Part.LayerName=“Foreground”
go:Part.SelectionElementName=“Ellipse”
go:Part.SelectionAdorned=“True”
go:Part.Resizable=“False”
go:Node.LocationSpot=“Center”
go:Node.Avoidable=“False” go:Node.LinkableFrom=“True” go:Node.LinkableTo=“True”
go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">


</go:NodePanel>

</go:DataTemplateDictionary>
</FrameworkElement.Resources>

<Grid.RowDefinitions>


</Grid.RowDefinitions>
<go:Palette
x:Name=“palette” MaximumSelectionCount=“1”
NodeTemplateDictionary="{StaticResource TemplateDictionary}"
Grid.Row=“0” Background=“LightBlue”>
go:Palette.Layout
<go:GridLayout Alignment=“Position” CellSize=“5 5”></go:GridLayout>
</go:Palette.Layout>
</go:Palette>
<go:Diagram
x:Name=“myDiagram”
NodeTemplateDictionary="{StaticResource TemplateDictionary}"
Grid.Row=“1” Background=“Azure” AllowDrop=“True”>
</go:Diagram>

Code behind - approach 1
var palettemodel = new MyModel();
palettemodel.NodesSource = new List()
{
new ProcessData() { Key=“P”, Text=“Process Unit” },
new ValveData() { Key=“V”, Text=“Valve”},
};
palette.Model = palettemodel;

With this approach, I am able to assign the nodes the the node template, but I am not allowed to drag the node to the diagram.

Code behind - approach 2
List nodesSource = new List()
{
new ProcessData() { Key=“P”, Text=“Process Unit” },
new ValveData() { Key=“V”, Text=“Valve”},
};

palette.NodesSource = nodesSource;

With this approach, I am able to drag the node to the diagram, but the node template is not assigned…

You didn’t say how you are initializing the target diagram’s model, but my guess is that it is not an instance of MyModel.

In order to allow drag-and-drop between different Diagrams, the models and the transferred data have to be compatible. The default model for a Diagram is a UniversalGraphLinksModel, which is clearly different from a MyModel.

Of course there will be situations where the models are of the same type but that you don’t want drag-and-drop to be permitted between a particular pair of diagrams. That is what the DiagramModel.DataFormat property is for.

Thank you, now it works :)