【发布时间】:2013-08-22 14:12:16
【问题描述】:
我已将代码更改为:
观点:
<phone:Panorama.ItemTemplate>
<DataTemplate>
<ScrollViewer Width="800" HorizontalContentAlignment="Left" Margin="0,50,0,0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox x:Name="list_of_images" ItemsSource="{Binding ImagesUrls}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Width="300" Height="300" Source="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ListBox>
<TextBlock Text="{Binding Title}"
Grid.Row="1"
Loaded="TextBlock_Loaded_1"
Margin="50,0,0,0"
FontSize="23"
TextWrapping="Wrap"
Width="360"
HorizontalAlignment="Left"
Foreground="Black"/>
<TextBox Text="{Binding ContactEmail}"
Grid.Row="2"
BorderBrush="Black"
Width="340"
HorizontalAlignment="Left"
BorderThickness="1"
Margin="40,0,0,0"
Foreground="Black" />
<TextBlock Text="{Binding Body}"
Grid.Row="3"
TextWrapping="Wrap"
Foreground="Black"
Margin="50,5,0,0"
Width="360"
HorizontalAlignment="Left"
FontSize="20" />
</Grid>
我构建了一个具有不同属性的新对象,其中一个属性是代表图像网址的字符串列表,但我无法显示图像?
我附上了屏幕截图,我必须更改我的 xaml 中的哪些内容才能显示图像,因为目前它没有显示任何图像,但它显示了所有其他详细信息
填充集合的代码:
ObservableCollection<ClassifiedAds> klasifiseerd_source = new ObservableCollection<ClassifiedAds>();
ImagesClassifieds new_Classifieds = new ImagesClassifieds();
ObservableCollection<string> gallery_images = new ObservableCollection<string>();
new_Classifieds.Title = klasifiseerd_source[0].Title;
new_Classifieds.ContactEmail = klasifiseerd_source[0].ContactEmail;
new_Classifieds.Body = klasifiseerd_source[0].Body;
foreach (var item in klasifiseerd_source[0].Gallery.Images)
{
var deserialized = JsonConvert.DeserializeObject<GalleryImages>(item.ToString());
gallery_images.Add(deserialized.ImageUrl);
//new_Classifieds.ImageUrls.Add(deserialized.ImageUrl);
}
new_Classifieds.ImageUrls = gallery_images;
// classifiedPanorama.ItemsSource = new_list;
new_Classifieds_list.Add(new_Classifieds);
classifiedPanorama.ItemsSource = new_Classifieds_list;
public class ImagesClassifieds
{
public string Title { get; set; }
public string ContactEmail { get; set; }
public string Body { get; set; }
public ObservableCollection<string> ImageUrls { get; set; }
}
这是 imageurl 格式,它可以工作(在我的应用程序的另一个部分中,我只需绑定到这种格式的 1 个图像,它就可以完美地工作)
【问题讨论】:
-
如何将图像列表绑定到单个图像控件?您是否在谈论 ItemsControl 的 ItemTemplate 中的 Image 控件?也许这会有所帮助:Binding to Collections.
-
你介意帮助我吗,所以我添加了这个:
但它仍然不工作,我做错了什么? -
您的图片网址是什么样的?请显示填充 ImageUrls 集合的代码。您是否看过 Visual Studio 中的输出窗口?也许它显示了一些绑定错误消息。
-
没有绑定问题,但是可以在全景项目模板中做一个列表框项目模板吗?但我认为我的 xaml 绑定代码是错误的
-
除了你不应该在第一个网格行(包含 ListBox)上设置
Height="Auto"之外,XAML 看起来没问题。对于 URL,您是否检查过它们是否真的有效?也许只是拿他们中的第一个做一个简单的测试:<Image Source="<url>"/>。
标签: xaml binding windows-phone