AddNode/RemoveNode

3 posts, 0 answers
  1. Mark Jakes
    Mark Jakes avatar
    27 posts
    Member since:
    Feb 2010

    Posted 27 Aug 2012 Link to this post

    Hello

    I was playing around with the ObservableGraphSourceBase in my MVVM test area and was attempting to attach/detach a PropertyChanged delagate to a node when it is added and/or removed.

    I checked the docs and implemented AddNode, RemoveNode and CreateNode, however, I cannot find 'RemoveNode' in the base class, but I do find 'RemoveItem'.

    Can you let me know if I should implement RemoveItem instead of RemoveNode or if I am interpreting the docs incorrectly.  What is the difference and what should I use in this instance?

    Many thanks

    Mark.

    RadControls for Silverlight, v.2012.2.725.1050, VS2010



    namespace MyApp2.ViewModel
    {
        public class ItemsDiagramObservableGraphSource : ObservableGraphSourceBase<DiagramObject, DiagramConnector>
        {
            public override void AddNode(DiagramObject node)
            {
                base.AddNode(node);
                node.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(node_PropertyChanged);
            }
      
            public override void RemoveNode(DiagramObject node)
            {
                base.RemoveNode(node);
                node.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(node_PropertyChanged);
            }
      
            Public void node_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                //  
            }
      
      
            public override object CreateNode(Telerik.Windows.Diagrams.Core.IShape shape)
            {
                var customobject = shape as CustomObject;
     
                if (shape != null)
                {
                    DiagramObject dobj=new DiagramObject();
      
                    dobj.Background = customobject.Background;
                    dobj.Foreground = customobject.Foreground;
                    // etc
                    return dobj;
                }
                else base.CreateNode(shape);
            }
        }
    // etc.
    }
     
     
    public class DiagramObject : NodeViewModelBase
    {
        public System.Windows.Media.Brush Background { get; set; }
            public System.Windows.Media.Brush Foreground
            {
                get
                {
                    // Calculate foreground colour based on background, back out if background is null
                     
                    if (this.Background == null) return null;
     
                    // Calculate contrast colour
                    byte d = 0;
                    byte achannel = 255;
     
                    SolidColorBrush S = this.Background as SolidColorBrush;
                    Color color = S.Color;
     
     
                    // Counting the perceptive luminance
                    double a = 1 - (0.299 * color.R + 0.587 * color.G + 0.114 * color.B) / 255;
     
                    if (a < 0.5)
                        d = 0; // bright colors - black font
                    else
                        d = 255; // dark colors - white font
     
                    return new SolidColorBrush(Color.FromArgb(achannel, d, d, d));
                }
                set {}
            }
             
    // etc
    }
  2. Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 30 Aug 2012 Link to this post

    Hello Mark Jakes,

     The IObservableGraphSource interface is implemented by our ObservableGraphSourceBase class Explicitly and there is no RemoveNode virtual method that you can override. The implementation of the IObservableGraphSource.RemoveNode method calls the RemoveItem from the base GraphSourceBase class, which is virtual and you can override it. Basically yes, you can use the RemoveItem method if you need to do something when an item has been removed from the diagram. 
    Let us know if you have further questions. 

    All the best,
    Miro Miroslavov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Mark Jakes
    Mark Jakes avatar
    27 posts
    Member since:
    Feb 2010

    Posted 30 Aug 2012 Link to this post


    Hello Miro

    Thanks for your reply, that is nice and clear now.

    Regards

    Mark.
Back to Top