0

I have the following DataTemplate for a listbox:

<DataTemplate x:Key="MoviesTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding S_Poster}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
                <StackPanel Orientation="Vertical" Width="200">
                    <TextBlock Text="{Binding Name}" FontSize="20"/>
                    <TextBlock Text="{Binding Type}" FontSize="16"/>
                    <TextBlock Text="{Binding Theaters_S}" FontSize="16"/>
                </StackPanel>
                <StackPanel ItemsSource="To be bound to the custom stack"/>
            </StackPanel>
        </DataTemplate> 

I need to bind the stack "StackPanel ItemsSource="To be bound to the custom stack" to a stackpanel i define in C# code named "Stack_PIC" referring to a stack of pics which is coded as follows:

for (int i=0; i < full; i++)
{
   Image star = new Image();
   star.Source = new BitmapImage(new Uri("/Images/Small_F.png", UriKind.Relative));
   d.Rating_PIC.Children.Add(star);
}  

My purpose behind this is to add rating stars to the ListBoxItems, So what is the correct way to bind the content of this stack to the following custom content??

UPDATE:

I kow that the stackpanel can't be bind this way and the alternative is to use a structure called ItemsControl as shown in this Question. However, i didn't understand the complete answer there and how to map it to my case so any help to clarify this is appreciated.

Community
  • 1
  • 1
Ameen
  • 1,857
  • 2
  • 23
  • 30

1 Answers1

0

You can't define an ItemsSource on a StackPanel. So you should try to solve your problem using a ListBox or some other ItemsControl object.

This post should get you on the way.

Also, perhaps consider using a premade starrating control (which I think you are trying to do, right?) , take a look at this one.

Community
  • 1
  • 1
Tim Dams
  • 747
  • 1
  • 6
  • 15