I have the following ListView
:
<ListView
Grid.Row="1"
ItemsSource="{Binding MeditationDiary}" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ElementName=ListViewHeaders, Path=ActualWidth}" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Text="{Binding StartTime}" />
<TextBlock
Grid.Column="1"
Text="{Binding TimeMeditated}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is bound to a MeditationDiary
property of type MeditationDiary
consisting of MeditationEntries
:
public class MeditationDiary : Collection<MeditationEntry> { }
public class MeditationEntry
{
public DateTime StartTime { get; set; }
public TimeSpan TimeMeditated { get; set; }
}
The ListView
binds to this MeditationDiary
:
private MeditationDiary _meditationDiary;
public MeditationDiary MeditationDiary
{
get
{
RaisePropertyChanged(nameof(MeditationDiary));
return _meditationDiary;
}
set
{
_meditationDiary = value;
RaisePropertyChanged(nameof(MeditationDiary));
}
}
Strangely enough when I assign a new MeditationDiary
object to the property (which contains data with MeditationEntries
) the ListView
does no longer display data.
I'm assigning the new MeditationDiary
object in the UpdateDiary
method which is called after adding an entry:
private async void UpdateDiary()
{
var latestDiary = await _repository.GetAsync();
MeditationDiary = latestDiary;
}
Why can this be and how can it be fixed?