Ok, So I have tried to implement a coverflow found on codeplex http://silverlightcoverflow.codeplex.com/
I wanted to use my own class for data binding:
class CoverItem
{
BitmapImage _image;
string _title;
string _link;
string _content;
public BitmapImage Image
{
get { return _image; }
set { _image = value; }
}
public string Title
{
get { return _title; }
set { _title = value; }
}
public string Link
{
get { return _link; }
set { _link = value; }
}
public string Content
{
get { return _content; }
set { _content = value; }
}
}
This is the XAML for the Cover User Control from codeplex:
<custom:CoverFlowControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding Image}" Width="300" />
<TextBlock Text="{Binding Title}" Width="300" />
<TextBlock Text="Testing" Width="300" />
</StackPanel>
</DataTemplate>
</custom:CoverFlowControl.ItemTemplate>
The problem I am having is that I get word “Testing” for each element that was bound, but I am not getting image or the title, which are from my objects that attached to the ItemSource property of the control.
Covers.ItemsSource = _items;
My question is, where am I going wrong? This should be a simple binding, so think I am missing something.
Thanks in advance for the help.
EDIT:
If I change the code to this:
List<BitmapImage> images = new List<BitmapImage>() { _items[0].Image, _items[1].Image, _items[2].Image, _items[3].Image };
Covers.ItemsSource = images;// _items;
And then have the binding as this:
<Image Source="{Binding}" Width="300" />
I now get my images displaying. So I know it is a problem with the binding somewhere.
Have also tried
<Image Source="{Binding Path=Image}" Width="300" />
Make the
CoverItemclass public. One of the downsides of Silverlight is reflection permission on internal Types across assemblies is not allowed. When binding to CLR properties, reflection is used to get the value. The assembly that’s trying to get the value is System.Windows, and it won’t have permission to reflect an internal Type in your assembly.I’ve written about this in context of anonymous Types (which are internal Types):
http://surrealization.com/blog/silverlight-anonymous-type-binding-gotcha/
Alternately you can provide an InternalsVisibleTo attribute on your assembly to allow System.Windows to “see” your internal Type.
http://grahammurray.wordpress.com/2010/05/30/binding-to-anonymous-types-in-silverlight/
For from-the-horse’s-mouth description, see this MSDN link:
http://msdn.microsoft.com/en-us/library/stfy7tfc(VS.95).aspx
And
http://connect.microsoft.com/VisualStudio/feedback/details/526229/in-silverlight-4-binding-to-an-internal-data-by-code-doesnt-work