I have a custom object type dependency property that is being populated at runtime. It is updated correctly, and the corect information is being stored in this object.
However, when I try to bind a property of this object to a textblock, no text appears (despite it definitely having data).
So, let’s say the object type is as follows :
Public class CustomObject{
[Key]
public int Id { get; set; }
public string Name { get; set; }
}
This object is definitely being populated, I have verified this with breakpoints.
I create a dependency property of this objects type, which definitely works correctly – this has also been verified. Let’s call the dependency property SelectedCustomObject.
And I bind this dependency property to my view :
<TextBlock Text="{Binding SelectedCustomObject.Name, Mode=TwoWay}" FontSize="10" VerticalAlignment="Center" HorizontalAlignment="Center"/>
The DataContext is set in my user control, and this definitely works as I have made several bindings to other dependency properties in the same view model and they work perfectly.
Therefore, by process of elimination I can only assume that my XAML syntax is off and you cannot bind to my populated and working dependency property like this.
Can anyone shed some light on this for me please ?
The answer to my question turned out to be that Silverlight was maintaining a separate cache and thus my new dependency property was, for whatever reason, not loading.
I deleted and regenerated my .XAP file, nothing.
I cleared my IE cache, nothing.
I opened Microsoft Silverlight from my start menu, went to the Application Storage tab and deleted all – then when I refreshed, all of my work appeared.
Happy days.
Hope this helps someone else :).