0

私は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>

何か案は?

4

2 に答える 2

0

BitmapImage1つは、実際にロングハンドコードを実行する必要がないことです。またはをそのプロパティに直接バインドするImage制御スパイポート。また、渡すURIが正しい形式であると確信していますか?正しく機能させるために、パッケージ名のプレフィックスを前面に付ける必要がある場合があります。ImageSourceURISource

于 2012-10-08T18:57:11.597 に答える
0

プログラムによる画像ソースの変更を参照してください

基本的:

<Image Margin="5" Source="{Binding BMImage}" Height="100"/>

BitmapImage bmImage;
public BitmapImage BMImage
{
    get
    {
        return bmImage;
    }
}

bmImage = new BitmapImage();
bmImage.UriSource = new Uri(new Uri(
     *your file path*, 
     *your image name*);

その他の例については、こちらのブログを参照してください。

于 2012-10-08T18:59:28.647 に答える