In my project, I have a timeline that is updated every second or so.
At each second, an Item with a duration representing the elapsed time is updated : its duration is modified.
When only the duration of one item changes, the timeline is redrawn when the VisibleStartDate and/or VisibleEndDate are changed.
If the visible zone is not changed, the only way to make the new duration of the item appear on the timeline is to use the Setter on ItemsSource. But this results in poor performances, most notably because I have implemented a mechanism that remembers the selected items when the Data is refreshed (it reselects it).
So in order to only redraw the timeline without having to update the ItemSource, I resolved to this uglyhack (that works, though).
In the view model.
public void UpdateItemDurationAndRefresh()
{
itemWithDuration.Duration = GetNewTimeSpan();
this.VisibleDate = this.VisibleDate.AddMilliseconds(-1);
this.VisibleDate = this.VisibleDate.AddMilliseconds(1);
}
I tried the following, but the duration of the item is not visible until some other interactions either changes the visible zone, or the ItemSource is actually updated.
public void UpdateItemDurationAndRefresh() // DOES NOT WORK
{
itemWithDuration.Duration = GetNewTimeSpan();
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Data"));
// "Data" is the name of the collection containing "itemWithDuration",
// and is binded to the GUI thanks to the XAML code
}
Is there anyway to redraw the timeline without having to reset the ItemSource, just like what is done when the visible zone is modified ?
Thanks