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
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
}