【发布时间】:2017-04-30 08:17:36
【问题描述】:
我正在尝试在 Windows 应用程序中将默认图片库中的所有图像显示到 ListView,但我只能显示图像的名称而不是文件夹中的所有图像,这是我的代码。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage.Streams;
using Windows.Storage;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ListView
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
showall();
}
public async void showall()
{
IReadOnlyList<StorageFile> file = await KnownFolders.PicturesLibrary.GetFilesAsync();
foreach (StorageFile file1 in file)
{
list.Items.Add(file1.Name);
}
}
这里是 xaml 代码...
<Page
x:Class="ListView.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ListView"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<StackPanel HorizontalAlignment="Left" Width="350" Height="350">
<ListView Width="300" Height="300" Name="list" SelectionChanged="list_SelectionChanged">
<Image Width="200" Height="200" Name="img"></Image>
</ListView>
</StackPanel>
<StackPanel VerticalAlignment="Top">
<Image Width="300" Height="300" Name="img1" />
<TextBlock Width="300" Height="30" Name="txt1" />
</StackPanel>
</StackPanel>
</Grid>
【问题讨论】:
-
这里是listView设计的图片链接:prntscr.com/djhu3f
-
那么问题出在哪里?用于绑定此的 xaml 在哪里?
-
@AVKNaidu 编辑检查以上
标签: c# xaml listview windows-store-apps uwp