小编use*_*252的帖子

如何在ListView中显示实际图像而不是它的位置?

我发现此代码将图片添加到WPF中的ListView.但是它只显示图像位置而不是实际图像:

            var image = new BitmapImage();

            string fileName = @"C:\Peak Sourcing\Work\ppt_test\slides_png\slide1.png";

            using (var stream = new FileStream(fileName, FileMode.Open))
            {
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.StreamSource = stream;
                image.EndInit();
            }


            ListBoxItem item = new ListBoxItem();
            Thumbnails.Items.Add(image);
Run Code Online (Sandbox Code Playgroud)

背后的XAML很简单:

<ListView Name="Thumbnails" Margin="10,10,804,10" >
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="1"/>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>



 </ListView>
Run Code Online (Sandbox Code Playgroud)

我还发现其他几个代码,但它们只是将图像位置显示为字符串而不是图像.你能帮我解决一下吗?

c# wpf xaml

3
推荐指数
1
解决办法
555
查看次数

标签 统计

c# ×1

wpf ×1

xaml ×1