【发布时间】:2015-01-25 19:02:33
【问题描述】:
我正在使用 Flickr.NET API 在空闲时间学习 WPF。
我要执行的第一个功能是按名称/描述/标签搜索图像。这导致我在 WPF 中使用图像。
这是我的设置:
- XAML
<Grid>
<ItemsControl x:Name="PhotoList" HorizontalAlignment="Left" Height="639" Margin="10,10,0,0" VerticalAlignment="Top" Width="1060" Style="{DynamicResource ScrollableItemControlStyle}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Height="639" Width="1060"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type sys:String}">
<Image Width="200" Source="{Binding Url}" Margin="0,0,5,5" MouseDown="OpenSelectedImage" MouseEnter="Image_MouseEnter" MouseLeave="Image_MouseLeave">
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button x:Name="BackButton" Style="{DynamicResource ModernButtonStyle}" Content="Back" HorizontalAlignment="Left" Margin="710,654,0,0" VerticalAlignment="Top" Width="360" Height="56 " TabIndex="2" Background="#FF6600CC" IsDefault="True" Foreground="White" Click="BackButton_Click"/>
</Grid>
- C#
public ObservableCollection<PhotoResult> images;
public ImageSearchResult(List<PhotoResult> imageList)
{
InitializeComponent();
if (imageList.Count > 0)
{
images = new ObservableCollection<PhotoResult>();
foreach (var image in imageList)
{
images.Add(image);
}
PhotoList.ItemsSource = images;
}
}
我们能做到吗:
- 我的 WrapPanel 根本不滚动。
- 当鼠标悬停在图像控件上时,我可以更改它们的大小(带有动画)以指示选择。但它覆盖了其他控件,而不是重新排列位置。我们能解决这个问题吗?我认为 ZIndex 在这种情况下不能按预期工作。
- 另外,我们可以在选择时更改图像边框吗?我暂时做不到。
【问题讨论】: