This is a migrated thread and some comments may be shown as answers.

AddNode/RemoveNode

2 Answers 106 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Mark Jakes
Top achievements
Rank 1
Mark Jakes asked on 28 Aug 2012, 12:12 AM
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 Answers, 1 is accepted

Sort by
0
Miro Miroslavov
Telerik team
answered on 30 Aug 2012, 06:01 AM
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.

0
Mark Jakes
Top achievements
Rank 1
answered on 30 Aug 2012, 10:36 PM

Hello Miro

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

Regards

Mark.
Tags
Diagram
Asked by
Mark Jakes
Top achievements
Rank 1
Answers by
Miro Miroslavov
Telerik team
Mark Jakes
Top achievements
Rank 1
Share this question
or