tags:

views:

578

answers:

3
A: 

Hard to say without seeing the XAML, but my first thoughts are either 1) you have not set the DataContext property to the ViewModel or 2) you have some syntax issue in the Binding itself.

You should use ObservableCollection instead of IEnumerable<DirectoryModel> to support DataBinding. I'm also not sure the implementation of your DirectoryDetails getter is beneficial. Your setter sets the private variable directly and fires the PropertyChanged event - this is proper. But your getter also sets the variable directly, bypassing the PropertyChanged event. Not to mention that you have a getter doing the work of a setter, which is probably a bad idea on several levels. I think you would be better to simplify your getter and have it just return the private variable. Do you really need to retrieve teh details everytime or can you use the local variable?

I would also point out that you do not need to implement INotifyPropertyChanged on your Model: the ViewModel needs this interface to support DataBinding, but there is no real value in adding it to the Model class.

Joel Cochran
I have managed to show my xaml now, can you please help!!
netmatrix01
I don't know if you still need help or not, but as I mentioned above, I do not see where you set the DataContext. Your DirectoryViewModel object needs to be defined as a DataSource, and then instantiated and referenced somewhere:Add a reference to your Namespace:xmlns:YourNamespace="clr-namespace:YourNamespace;assembly=YourAssembly"In your Resources:<YourNamespace:DirectoryViewModel x:Key="myDataSource" d:IsDataSource="True"/> Then add the data source as your DataContext:<Grid DataContext="myDataSource">
Joel Cochran
Sorry - DataContext should be like this: DataContext="{Binding Source={StaticResource myDataSource}}"
Joel Cochran
+6  A: 

I cant remember where i got this technique from but its really useful when used to debug bindings

add a class to the project called Debugconverter

public class DebugConverter : IValueConverter {
  public object Convert(object value,
     Type targetType, object parameter,
     System.Globalization.CultureInfo culture) {

     return value; //set the breakpoint here
  }

  public object ConvertBack(object value,
   Type targetType,
   object parameter,
   System.Globalization.CultureInfo culture) {

     return value;
  }

}

then i add a reference to it in app.xaml

     <currentProjectNamespace:DebugConverter
        x:Key="debugConverter" />

then use it in a binding,

Binding="{Binding Path=PropertyName, Converter={StaticResource debugConverter}}"

when the binding happens you get a breakpoint hit, i would be screwed without it. Also check the output window, there is alist of binding failures there.

Aran Mulholland
great idea. I am about to need to do some heavily databound controls and this (debugging databinding) was one of the things I was not sure how to address.
Anthony Potts
on of the tricks i use to debug bindings all the time is to set "Path=." in my binding to see what it is trying to bind to, often its not the object you expect.
Aran Mulholland
A: 

would be helpful to know what the problem is... never the less, the questions i would ask are :-

are your getters being hit (put a breakpoint in them)?

is the first list view working, and the second one not?

if it is only the second that is failing i would guess that the problem is that you are trying to bind two columns to the property IEnumerable FileDetails, and then you are trying to follow a property path on a IEnumerable, which will not work, as it is a group of objects, not one. have you copied and pasted your code from the listview above and not set the items source correctly?

what is in your output window when you run? it usually tells you that a binding path could not be found. if you follow the debug converter suggestion above, you can find out what you are binding to (if anything)

Aran Mulholland