我是 xaml 编程的新手。我一直在尝试将多个图像绑定到列表框,但没有成功。我可以在 winrt 应用程序中看到文本,但看不到图像。下面是代码:
Imports Windows.Storage.Pickers
Imports Windows.Storage
Public NotInheritable Class MainPage
Inherits Page
Dim p As System.Uri
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached. The Parameter
''' property is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
End Sub
Private Async Sub SelectFileName_Click(sender As Object, e As RoutedEventArgs) Handles _SelectFileName.Click
Dim SelectedFileNameObject As New FileOpenPicker
SelectedFileNameObject.FileTypeFilter.Add("*")
Dim SelectedFileName As IReadOnlyList(Of StorageFile) = Await SelectedFileNameObject.PickMultipleFilesAsync
Dim a As New ObservableCollection(Of ImageLoc)
For i As Integer = 0 To SelectedFileName.Count - 1
p = New Uri(SelectedFileName.Item(i).Path.ToString, UriKind.RelativeOrAbsolute)
a.Add(New ImageLoc() With {.ImageLocation = _SelectedFileName.Item(i).Path.ToString, .LineFour = p})
Next
ListName.ItemsSource = a
End Sub
End class
Public Class ImageLoc
Public location As String
Property ImageLocation() As String
Get
Return location
End Get
Set(ByVal value As String)
location = value
End Set
End Property
Public b As Uri
Public Property LineFour() As Uri
Get
Return b
End Get
Set(ByVal value As Uri)
b = value
End Set
End Property
End Class
Xaml 是:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Height="auto" Width="auto" Orientation="Horizontal">
<Button x:Name="SelectFileName" Width="100" Height="50" Content="Browse Files" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,40,0"/>
<ListBox x:Name="ListName" Width="700" Height="auto">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding ImageLocation}" Height="auto" Width="auto"/>
<Image Height="100" Width="100">
<Image.Source>
<BitmapImage UriSource="{Binding Path=LineFour}"/>
</Image.Source>
</Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
有任何想法吗?