Re: When the source of binding is null is not evaluated anymore. Is this a Binding bug?
Hello, can you post some code? I don't see any differences between WPF and Silverlight in this area.
If you have something like this:
public class Data : INotifyPropertyChanged
{
private string test;public string Test
{
get { return test; }
set
{
test = value;if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Test"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
In your main class, initially you have a null Data class:
private Data data;
Then you set data to a new instance of the Data class after you set DataContext, it doesn't work in both WPF and Silverlight. This is by design.
this.DataContext = data;
data =
new Data() { Test = "aaa" };
If, however, your data classes look like this:
public class Data : INotifyPropertyChanged
{
private Nested ne;public Nested Ne
{
get { return ne; }
set
{
ne = value;if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Ne"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class Nested : INotifyPropertyChanged
{
private string test;public string Test
{
get { return test; }
set
{
test = value;if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Test"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
In your main class, you initialized the parent class before you set the DataContext:
private Data data = new Data();
And after setting DataContext, you set the nested property to a new object, it works fine in both WPF and Silverlight.
this.DataContext = data;
data.Ne =
new Nested() { Test = "aaa" };
shanaolanxing - Please mark the posts as answers if they help and unmark if they don't.