Hi guys,
I have a query and I'm sure I've had the issue before yet the results from googling are bringing up the same thing which I have already implemented (in a fashion).
I have a MVVM application and one of the V-VM's is to display some file listings.
The viewModel has a read only observable collection property which looks like this:
public ReadOnlyObservableCollection<TemplateFileViewModel> ListOfTemplates
{
get
{
m_FileListing = new ObservableCollection<TemplateFileViewModel>();
if (!String.IsNullOrWhiteSpace(TemplateDirectoryPath))
{
foreach (var s in Directory.GetFiles(TemplateDirectoryPath, "*.MyEXT",
IncludeSubFolders ? SearchOption.AllDirectories :
SearchOption.TopDirectoryOnly))
{
m_FileListing.Add(new TemplateFileViewModel(s));
}
}
return new ReadOnlyObservableCollection<TemplateFileViewModel>(m_FileListing);
}
}
I also have a property "TemplateDirectoryPath" which looks like this:
public string TemplateDirectoryPath
{
get { return m_TemplateDirectoryPath; }
set
{
if (Equals(m_TemplateDirectoryPath, value) || !Directory.Exists(value)) return;
m_TemplateDirectoryPath = value;
OnPropertyChanged("TemplateDirectoryPath");
OnPropertyChanged("ListOfTemplates");
}
}
The idea is that when the TemplateDirectoryPath is updated it triggers a list box to refresh its contents, which is bound to the ListOfTemplates property on the view model.
No my understanding is that if I user the "OnPropertyChanged" event it should result in the view doing a data refresh.
My listbox is bound as follows:
<ListBox Grid.Column="0" ItemsSource="{Binding Path=ListOfTemplates, UpdateSourceTrigger=PropertyChanged}" ItemTemplate="{StaticResource TemplateFileDataTemplate}"/>
Why would this not be triggering an update on the screen? From what I can see it all appears correct, am I missing something really obvious?
Thanks