Hi,
I also did in the same way, but there are two issues:
- Images are still not visible.
- All nodes & links are moved to the top, irresespective to their location. They should not moved automatically.
Please provide me the solution using the following code:
MainPage.xaml:
<UserControl x:Class="Graph.MainPage"<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:go="http://schemas.nwoods.com/GoXam">
<UserControl.Resources>
<DataTemplate x:Key="NodeTemplate">
<StackPanel go:Node.SelectionElementName="Node"
go:Node.SelectionAdorned="True"
go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}"
go:Node.Movable="False"
go:Node.Resizable="False">
<TextBlock Text="{Binding Path=Data.Key}"/>
<Image Source="{Binding Path=Data.NodeImage}">
</Image>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="LinkTemplate">
<go:LinkShape Stroke="Black" StrokeThickness="1" />
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<go:Diagram Grid.Column="1"
x:Name="xDiagram"
BorderBrush="Blue" BorderThickness="1"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
NodeTemplate="{StaticResource
NodeTemplate}"
LinkTemplate="{StaticResource LinkTemplate}"
/>
</Grid>
</UserControl>
MainPage.xaml,cs code:
public
partial class MainPage
{
public MainPage()
{
InitializeComponent();
showDiagram();
}
private void showDiagram()
{
var model = new GraphLinksModel<MyNodeData, String, String, MyLinkData>();
model.NodesSource =
new ObservableCollection<MyNodeData>()
{
new MyNodeData() {Key = "Alpha", Location = new Point(100.0, 400.0)},
new MyNodeData() {Key = "Beta", Location = new Point(1000.0, 600.0)},
new MyNodeData() {Key = "Gamma", Location = new Point(1200.0, 400.0)},
new MyNodeData() {Key = "Delta", Location = new Point(2200.0, 400.0)}
};
model.LinksSource =
new ObservableCollection<MyLinkData>()
{
new MyLinkData() { From="Alpha", To="Beta" },
new MyLinkData() { From="Beta", To="Gamma" },
new MyLinkData() { From="Gamma", To="Delta" }
};
xDiagram.Model = model;
}
public
class MyNodeData : GraphLinksModelNodeData<String>
{
public Image NodeImage
{
get
{
_image =
new Image();
//Depot.ico is an image, which I added `Images` folder under ClientBin
ImageSource source = new BitmapImage(new Uri("/Images/Depot.ico", UriKind.Relative));
_image.Source = source;
return _image;
}
}
private Image _image;
}
public class MyLinkData : GraphLinksModelLinkData<String, String>
{
}