RadDiagramThumbnail Does Not Update For Node Visibility Changes

4 posts, 1 answers
  1. Michael
    Michael avatar
    26 posts
    Member since:
    Oct 2014

    Posted 04 Jun 2015 Link to this post

    I am using the RadDiagramThumbnail to show a thumbnail overview of the diagram, how it is implemented is very much like the example in the documentation for the DiagramNavigationPane (i.e. not a complicated or custom implementation).  Associated with the diagram is a treeview control by which the user can show/hide nodes by checking/unchecking in the tree (again, not too complicated I just have a node view model property bound to each node's Visibility property).  But I have noticed the following behavior with the RadDiagramThumbnail pane:

    If the thumbnail/navigation pane is open and the user moves a node in the diagram, the thumbnail will update, but if the user change's a nodes visibility (e.g. collapses one or more nodes), then the thumbnail does not update.  If nodes in the diagram are moved after a visibility change, then the thumbnail will update accordingly.

    How do I enable the thumbnail view to update when a node's visibility has been changed?

    Thanks,

    Mike

  2. Answer
    Martin
    Admin
    Martin avatar
    1099 posts

    Posted 09 Jun 2015 Link to this post

    Hi Michael,

    In order to achieve the desired effect you can use the RadDiagramNaigationPane's RefreshThumbnail() method when you change the visibility. 
    this.navigationPane.RefreshThumbnail();

    Please let me know if you need any further assistance.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Michael
    Michael avatar
    26 posts
    Member since:
    Oct 2014

    Posted 23 Jun 2015 in reply to Martin Link to this post

    Martin,

    Thanks for the answer, now I just have a few questions on how to implement it in my solution.  I am using an MVVM approach with the diagram.GraphSource bound to a object that inherits from ObservableGraphSourceBase.  Since I want to keep the view model as de-coupled as possible, I have been trying to attach event handlers to the shapes and connections and watch for a change in the Visibility property:

    //this is from the code behind file
    public BT()
    {
      InitializeComponent();
      
      diagram.GraphSourceChanged += new EventHandler(diagram_GraphSourceChanged);
      DataContext = new BTViewModel(new ClientServiceProvider());
    }
      
    void diagram_GraphSourceChanged(object sender, EventArgs e)
    {    
      foreach(var shape in diagram.Shapes)
        shape.PropertyChanged += shape_PropertyChanged;
      foreach (var conn in diagram.Connections)
        conn.PropertyChanged += connection_PropertyChanged;
    }
      
    void shape_PropertyChanged(object sender, PropertyEventArgs e)
    {
      if (string.Compare(e.PropertyName, "Visibility")==0 && navigationPane.Visibility == Visibility.Visible)
        navigationPane.RefreshThumbnail();
    }
      
    void connection_PropertyChanged(object sender, PropertyEventArgs e)
    {
      if (string.Compare(e.PropertyName, "Visibility") == 0 && navigationPane.Visibility == Visibility.Visible)
        navigationPane.RefreshThumbnail();
    }

    But, when a shape or connection has it's Visibility property changed, the PropertyChanged event is not fired and neither of the navigationPane.RefreshThumbnail() lines in the example above get called.  I did notice that when a shape is moved, the navigationPane does get refreshed and shows and updated view of the Diagram.  Is there a way I can get the default implementation of RadDiagramShape and RadDiagramConnection to fire the PropertyChanged event when Visibility is changed?  Or should I inherit from them to override the Visibility property (but in doing this I am not sure what other implications overriding Visibility would have):

     

    public class RadDiagramResourceShape : RadDiagramShape
    {
      public new Visibility Visibility
      {
        get
        {
          return base.Visibility;
        }
        set
        {
          if (base.Visibility != value)
          {
            base.Visibility = value;
            base.OnPropertyChanged("Visibility");
          }
        }
      }
    }
     
    public class RadDiagramRelationConnection : RadDiagramConnection
    {
      public new Visibility Visibility
      {
        get
        {
          return base.Visibility;
        }
        set
        {
          if (base.Visibility != value)
          {
            base.Visibility = value;
            base.OnPropertyChanged("Visibility");
          }
        }
      }
    }

     

    Any advice is much appreciated!

     

    Mike

  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 25 Jun 2015 Link to this post

    Hi Michael,

    Instead of subscribing for the PropertyChanged of the shapes and connection you can use the PropertyChanged event of their view models. Here is an example:
    void diagram_GraphSourceChanged(object sender, EventArgs e)
    {   
        var source = diagram.GraphSource as MyGraphSource;
        foreach(var node in source.InternalItems)
            node.PropertyChanged += node_PropertyChanged;
        foreach (var conn in source.InternalLinks)
            conn.PropertyChanged += link_PropertyChanged;
    }
    Please try this and let me know if it works for you.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top