【发布时间】:2023-03-15 02:24:01
【问题描述】:
我有以下用于列表框的 DataTemplate:
<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>
我需要将堆栈 "StackPanel ItemsSource="To be bound to the custom stack" 绑定到我在名为 "Stack_PIC" 的 C# 代码中定义的堆栈面板一堆图片,编码如下:
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);
}
我这样做的目的是将rating stars添加到ListBoxItems,那么将这个堆栈的内容绑定到以下自定义内容的正确方法是什么?
更新:
我知道堆栈面板不能以这种方式绑定,替代方法是使用名为 ItemsControl 的结构,如Question 所示。但是,我不明白那里的完整答案以及如何将其映射到我的案例中,因此感谢任何帮助澄清这一点。
【问题讨论】:
标签: xml windows-phone-7