I have list with items in my data class:
public ObservableCollection<Node> NodesFromDatabase
{
get
{
if (_nodesFromDatabase == null)
_nodesFromDatabase =GenerateMenuNodes();
return _nodesFromDatabase ;
}
set
{
_nodesFromDatabase = value;
}
}
And property in control to which i want bind this data:
public ObservableCollection<Node> Nodes
{
get { return (ObservableCollection<Node>)GetValue(NodesProperty); }
set
{
SetValue(NodesProperty, value);
}
}
private static DependencyProperty NodesProperty =
DependencyProperty.Register(
"Nodes",
typeof(ObservableCollection<Node>),
typeof(Control),new PropertyMetadata(new ObservableCollection<Node>()));
In xaml i have such code:
<Grid Background="White">
<Grid.DataContext>
<local:DataFromDataBase x:Name="database" />
</Grid.DataContext>
<local:Control Nodes="{Binding NodesFromDatabase}" />
</Grid>
And i have strange logic behind this code.
My NodesFromDatabase property is fired in get statement but control Nodes set statement not firing! What i am doing wrong with it?
Dependency properties that are set in XAML can bypass the CLR wrapper. You should create a property-changed callback in the property metadata if you want to know when the property is changed.