Articles in this section
Category / Section

How to use the property grid in the WPF Diagram (SfDiagram)?

1 min read

The PropertyGrid control can be used to show the properties of the selected object and able to change the values dynamically. The properties values will be updated dynamically based on the selected objects using the events of the WPF Diagram (SfDiagram) control.

C#

public partial class MainWindow : Window
{ 
  public MainWindow()
  {
    InitializeComponent();
    SfDiagram diagram = new SfDiagram();
    (diagram.Info as IGraphInfo).ItemSelectedEvent += MainWindow_ItemSelectedEvent;
    (diagram.Info as IGraphInfo).AnnotationChanged += MainWindow_AnnotationChanged;
  }
 
  private void MainWindow_AnnotationChanged(object sender, ChangeEventArgs<object, AnnotationChangedEventArgs> args)
  {
    if (args.Item is IAnnotation)
    {
      propertyGrid1.SelectedObject = args.Item;
    }
  }
        
  void MainWindow_ItemSelectedEvent(object sender, DiagramEventArgs args)
  {
    if (args.Item is INode)
    {
      propertyGrid1.SelectedObject = args.Item;
    }
    else if (args.Item is IConnector)
    {
      propertyGrid1.SelectedObject = args.Item;
    }
  }
}

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied