0
我需要我的項目的專家幫助。 請幫助我,我是WPF的新手,我使用VB.NET創建應用程序以顯示用戶選擇的文件夾中的圖片。在窗體上我把Button(按下選擇文件夾),Image(顯示從ListView中選擇的圖像),ListView(2列與第一列圖像縮略圖和第二列文件名)。 請檢查下面我的XAML代碼:圖像沒有顯示在第一列Listview WPF與VB.NET(第一列圖像,第二列字符串)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="MainWindow"
Title="MainWindow" Height="448.545" Width="698.135">
<Grid>
<Image x:Name="ImgView" Margin="259,44,10,72"/>
<Button Content="Pilih Folder" HorizontalAlignment="Left" Height="29" Margin="10,10,0,0" VerticalAlignment="Top" Width="92" Click="Button_Click"/>
<ListView x:Name="ListView1" HorizontalAlignment="Left" Height="351" Margin="10,44,0,0" VerticalAlignment="Top" Width="244">
<ListView.View>
<GridView>
<GridViewColumn Header="Gbr" DisplayMemberBinding="{Binding Gambar}"/>
<GridViewColumn Header="Nama File" DisplayMemberBinding="{Binding NamaFile}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
這裏是我的代碼隱藏
Imports System.Windows.Forms
Imports System.Collections.ObjectModel
Class MainWindow
Private _GbrCollection As New ObservableCollection(Of GambarCol)
Public ReadOnly Property GbrCollection() As ObservableCollection(Of GambarCol)
Get
Return _GbrCollection
End Get
End Property
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
InitializeComponent()
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim ImgList() As Image
Dim Img88 As Image
Dim fld As New FolderBrowserDialog
fld.RootFolder = Environment.SpecialFolder.Desktop
'fldDialog.RootFolder = Environment.SpecialFolder.Desktop;
fld.ShowDialog()
'txtPath.Text = fld.SelectedPath
'filesListBox.Items.Clear()
Dim fileNames = My.Computer.FileSystem.GetFiles(fld.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.jpg")
'Debug.WriteLine(fileNames.Count)
ReDim ImgList(fileNames.Count)
For Each fileName As String In fileNames
_GbrCollection.Add(New GambarCol(Img88, fileName))
Next
ListView1.ItemsSource = GbrCollection
End Sub
Private Sub ListView1_MouseDoubleClick(sender As Object, e As MouseButtonEventArgs) Handles ListView1.MouseDoubleClick
Dim ImgShow As New Image
If ListView1.SelectedItems.Count > 0 Then
End If
'ImgShow.Source = New BitmapImage(New System.Uri(ListView1.Items))
End Sub
Private Sub ListView1_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles ListView1.SelectionChanged
End Sub
End Class
Public Class GambarCol
Private _Gambar As Image
Private _NamaFile As String
Public ReadOnly Property Gambar() As Image
Get
_Gambar = New Image
_Gambar.Source = New BitmapImage(New System.Uri(NamaFile))
_Gambar.Height = 60
Return _Gambar
End Get
End Property
Public ReadOnly Property NamaFile() As String
Get
Return _NamaFile
End Get
End Property
Public Sub New(ByVal GbrImg As Image, ByVal NamaFileNF As String)
_Gambar = GbrImg
_NamaFile = NamaFileNF
End Sub
End Class
大師,幫我解決3個問題:1。 圖像不能顯示在列1列表視圖 2.如何從第2列的值,當用戶雙擊選定的行 3.我知道我的代碼太複雜了,有人可以幫我做簡單
真的真的需要幫助
非常感謝您
的人?我還沒有找到解決方案..謝謝 – user3540114 2014-10-29 04:50:11