I've been trying to follow examples and other peoples questions but I can't get this list view to bind to an ObservableCollection. I can't figure out what I'm doing wrong. Would appreciate if somebody can point out my mistake please.
MainWindow.xaml:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Duplicate_File_Finder"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListView ItemsSource="{Binding Path=dFileList}">
<ListView.View>
<GridView>
<GridViewColumn Header="File Name" DisplayMemberBinding="{Binding Path=FileName}" />
<GridViewColumn Header="Path" DisplayMemberBinding="{Binding Path=Path}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
MainWindow.xaml.vb:
Imports System.Collections.ObjectModel
Public Class DuplicateFile
Public Sub New(ByVal FileName As String, ByVal Path As String, ByVal Hash As String, ByVal Icon As String)
Me.FileName = FileName
Me.Path = Path
Me.Hash = Hash
Me.Icon = Icon
End Sub
Public Property Icon As String
Public Property FileName As String
Public Property Path As String
Public Property Hash As String
End Class
Class MainWindow
Public dFileList As New ObservableCollection(Of DuplicateFile)
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
For i = 0 To 1
dFileList.Add(New DuplicateFile("File " + i.ToString, "C:\File " + i.ToString, i.ToString, i.ToString))
Next
End Sub
End Class
DataContextofMainWindow? You could do it 1 of 2 ways: 1) setthis.DataContext = this, or 2) Set andx:Nameof yourMainWindowelement and then useElementName=to it, in order to use it as the context for your binding.this" thing! (I meantMe). It's becausedFileListis a field, not a property. Try setting it to a property (like you have with properties in theDuplicateFileclass) -Public Property dFileList As New ObservableCollection....