WPF:如何在列表视图中显示多个图像以供预览,底部每个图像上的图标允许用户删除

时间:2016-05-03 07:07:55

标签: wpf wpf-controls

enter image description here 我想以这种方式在列表视图中显示图像,我能够在列表视图中显示它们。请帮我介绍如何在图片上添加图标。

下面是我的列表视图代码并动态绑定图片,请发布任何样本热点以显示我的图像上的十字标记,点击事件我可以删除图像                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

1 个答案:

答案 0 :(得分:0)

对不起,我迟到了,但我真的很忙 您要做的是在ControlTemplate内创建一个Image 现在,您的ListView应该使用该模板来显示如下内容:

<ListView ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Template" Value="{StaticResource ctModules}"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

你的模板应该是这样的:

<ControlTemplate x:Key="ctModules">
    <Grid Height="150" Width="150">
        <Image Source="{Binding url}"/>
        <Image Source="{Binding PathToYourRedCrossImage}" Width="32" Height="32" MouseLeftButtonDown="Image_MouseLeftButtonDown" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
    </Grid>
</ControlTemplate>  

Image_MouseLeftButtonDown看起来像这样:

private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    //your logic here
}