Hi,
I have two diagrams-- yDiagram & xDiagram
There are different nodes assigned to both models.
Now I added a context menu ‘Delete’ on nodes of yDiagram.
Now I want to perform the following task:
If user click on ‘Delete’ context menu command of any node of yDiagram, then nodes of x diagram, which satisfy the following condition, should be automatically deleted:
xDiagram.Node.YAxisLabel == yDiagram.Text
But the issue is that the following line doesn’t give any information of selected node of ‘yDiagram’, so please have a look & provide me the solution:
varpartdata = ((FrameworkElement)sender).DataContext as PartManager.PartBinding;
.xaml Code:
<
Grid x:Name=“LayoutRoot” Background=“White”>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<go:Diagram Grid.Column="0"
x:Name="yDiagram"
BorderBrush="Blue" BorderThickness="1"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
DragSelectingTool="{x:Null}"
NodeTemplate="{StaticResource YAxisLabelNodeTemplate}">
<go:Diagram.DraggingTool>
<local:CustomDraggingTool Tag="{Binding ElementName=xDiagram}"/>
</go:Diagram.DraggingTool>
</go:Diagram>
<go:Diagram Grid.Column="1"
x:Name="xDiagram"
BorderBrush="Blue" BorderThickness="1"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
NodeTemplateDictionary="{StaticResource NodeTemplates}"
LinkTemplateDictionary="{StaticResource LinkTemplates}"
/>
</Grid>
<
DataTemplate x:Key=“YAxisLabelNodeTemplate”>
<StackPanel go:Node.SelectionElementName=“LabelNode”
go:Part.Selectable=“True”
go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
<menu:ContextMenuService.ContextMenu>
<menu:ContextMenu>
<menu:MenuItem Header=“Delete” Click=“OnDeleteContextMenuItemClick” >
<menu:MenuItem.Icon>
<Image Source="{Binding Path=Data.NodeImage}" Height=“20” />
</menu:MenuItem.Icon>
</menu:MenuItem>
</menu:ContextMenu>
</menu:ContextMenuService.ContextMenu>
<TextBlock Text="{Binding Path=Data.Text}"/>
</StackPanel>
</DataTemplate>
.cs Code:
private
void OnDeleteContextMenuItemClick(object sender, RoutedEventArgs e)
{
var partdata = ((FrameworkElement)sender).DataContext as PartManager.PartBinding;
if (partdata == null || partdata.Data == null)
{
MessageBox.Show("Clicked on nothing or on unbound part");
}
else
{
MessageBox.Show("Clicked on data: " + partdata.Data.ToString());
}
}