I'm trying to create a ListView of recent files that the user has opened in a program. I have used a custom object called GameFileData
that stores 3 variables, Path
(string), Name
(string) and LastEdited
(DateTime). These details are stored in a List object.
Here's the XAML for the ListView
<ListView x:Name="LvRecents" SelectionMode="Single" Margin="5,41,10,35">
<ListView.View>
<GridView>
<GridViewColumn x:Name="ColName" Header="Name" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn x:Name="ColLastEdited" Header="Last Edited" DisplayMemberBinding="{Binding LastEdited}"/>
</GridView>
</ListView.View>
</ListView>
In code-behind, I have a method that executes when the window loads:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LvRecents.Items.Clear();
List<GameFileData> gfd = Saves.GetRecents();
LvRecents.ItemsSource = gfd;
}
When I run the code with two items in the list, the ListView correctly displays two selectable items, but they have no contents:
I have also tried the same with the Path
variable instead of the LastEdited
, thinking maybe it's to do with the strange data structure, but I get the same result
Edit: As requested, the GameFileData class:
public class GameFileData
{
public string Path;
public string Name;
public DateTime LastEdited;
public GameFileData(string path, string name, DateTime lastEdited)
{
Path = path;
Name = name;
LastEdited = lastEdited;
}
}
Breakpoints have determined that GetRecents() returns the list correctly