On button click a GalaSoft.MvvmLight.Messaging message is triggered across all viewModels that have the message receiver registered. A new list of data is acquired asynchronously and used to update the UI. The UI updates but when I call the following
var contentControls = VisualTreeQueryHelper.FindChildrenOfType(this).ToList();
It still reflects the content count and indices of the old list even though the visual list on screen is correct. This breaks my focus logic that uses index and list size to set focus.
If I navigate away from the view and come back then the contentControls list is corrected.
private IList<CoreViewModel> itemViewModels;
public IList<CoreViewModel> ItemViewModels
{
get { return this.itemViewModels; }
set
{
this.itemViewModels = value;
RaisePropertyChanged("ItemViewModels");
}
}
public static IEnumerable<T> FindChildrenOfType<T>(DependencyObject objectInParentTreeToStartFrom)
where T : DependencyObject
{
List<T> list = new List<T>();
FindChildrenOfTypeImpl<T>(objectInParentTreeToStartFrom, list);
return list;
}
private static void FindChildrenOfTypeImpl<T>(DependencyObject objectInParentTreeToStartFrom, List<T> list)
where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(objectInParentTreeToStartFrom); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(objectInParentTreeToStartFrom, i);
if (child is T)
{
list.Add(child as T);
}
else
{
FindChildrenOfTypeImpl(child, list);
}
}
}