This is a migrated thread and some comments may be shown as answers.

Bind Images to RadDataBoundListBox

1 Answer 137 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Robert
Top achievements
Rank 1
Robert asked on 12 Apr 2011, 11:17 AM
 

It's my understanding that the RadDataBoundListBox for Windows Phone 7 does not support direct content.

My goal is to load 12 images from a folder named Images, and I am trying to bind an image (defined in the application folder named Images) to the RadDataBoundListBox.

During testing, 12 lines of System.Windows.Media.Imaging is displayed on the Windows Phone 7 - rather than 12 instances of the hard-coded image.

Any insight is appreciated, and the below code is being utilized in this test case.

BitmapImage 

 

 

bi3 = new BitmapImage();
 

 

 

bi3.UriSource = 

 

new Uri("Images/GreenPea.png", UriKind.Relative); 

 

 

 

 

ObservableCollection 

<BitmapImage> months = new ObservableCollection<BitmapImage>();

 

 

 

 

 

 

foreach (string monthName in DateTimeFormatInfo.CurrentInfo.MonthNames)

 

 

{

    months.Add(bi3);

 

}

 

 

 

this.radDataBoundListBox.ItemsSource = months;

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 13 Apr 2011, 01:38 PM
Hello Robert ,

Thanks for contacting us.

In order for your approach to work as expected, you will have to additionally define a special DataTemplate for your items which will contain an Image which you will use to display the BitmapImage instances in your collection. This is the default way of representing any type of special content in Silverlight. Take a look at the following XAML code snippet:

<telerikPrimitives:RadDataBoundListBox>
      <telerikPrimitives:RadDataBoundListBox.ItemTemplate>
            <DataTemplate>
                  <Image Source="{Binding <Path_to_the_Image_Source>}"/>
            </DataTemplate>
       </telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>

As you can see, I have defined a DataTemplate which contains an instance of the Image class. The Image class is the visual representation of an image in the visual tree. You can also see that I am using the Source property of the Image class and bind it to the path to the image in the business object (the object that comes from the collection I have used to fill my listbox). If you want to bind directly to the business object instead of a property, simply use Source={Binding}.

I hope this helps.

Do not hesitate to get back to us in case you have further questions or need assistance.

Regards,
Deyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
DataBoundListBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or