[UWP] [Xaml] Gridview显示图像库不工作

编程入门 行业动态 更新时间:2024-10-22 17:35:14
本文介绍了[UWP] [Xaml] Gridview显示图像库不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经尝试了各种方法来绑定gird项模板中的动态图像的路径,似乎没有任何工作。照片路径在图片文件夹中的事实是否重要?下面是我目前的代码,任何指针或反馈都是非常感谢:

I have tried all kinds of ways of binding the path of dynamic images in the gird item template and nothing seems to work. Does the fact that the photo path are in the Pictures folder matter? Below is the code I currently have, any pointer or feedback are greatly appreciated:

XML

< RelativePanel> < GridView x:Name =" AlbumPhotos" SelectionMode =" Multiple" < GridView.ItemTemplate> < DataTemplate x:Name =" ImageGalleryDataTemplate" x:DataType =" storage:StorageFile"> < Image Source =" {x:Bind Path}"高度= QUOT; 180"宽度= QUOT; 180" Stretch =" UniformToFill" /> < / DataTemplate> < /GridView.ItemTemplate> < GridView.ItemsPanel> < ItemsPanelTemplate> < ItemsWrapGrid MaximumRowsOrColumns =" 6" Orientation =" Horizo​​ntal" /> < / ItemsPanelTemplate> < /GridView.ItemsPanel> < / GridView> < / RelativePanel>

<RelativePanel> <GridView x:Name="AlbumPhotos" SelectionMode="Multiple"> <GridView.ItemTemplate> <DataTemplate x:Name="ImageGalleryDataTemplate" x:DataType="storage:StorageFile"> <Image Source="{x:Bind Path}" Height="180" Width="180" Stretch="UniformToFill"/> </DataTemplate> </GridView.ItemTemplate> <GridView.ItemsPanel> <ItemsPanelTemplate> <ItemsWrapGrid MaximumRowsOrColumns="6" Orientation="Horizontal"/> </ItemsPanelTemplate> </GridView.ItemsPanel> </GridView> </RelativePanel>

C#

推荐答案

您好,

您无法将路径绑定到 Image.Source 属性直接。您需要将其转换为BitmapImage对象并将BitmapImage绑定到Image.Source属性。像这样:

You could not bind the path to the Image.Source property directly. You need to convert it to a BitmapImage object and bind the BitmapImage to the Image.Source property. Like this:

using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) { // Set the image source to the selected bitmap BitmapImage bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(fileStream); }

然后像这样绑定bitmapimage:

Then bind the bitmapimage like this:

<Image Source="{x:Bind bitmapImage}" Height="180" Width="180" Stretch="UniformToFill"/>

您可以在此处获取有关如何加载图像文件的更多信息:图像类

You could get more information about how to load an image file here:Image Class

最好的问候,

Roy

更多推荐

[UWP] [Xaml] Gridview显示图像库不工作

本文发布于:2023-11-10 16:01:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   工作   UWP   Xaml   Gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!