views:

784

answers:

2

I am attempting to bind a ListView control to a DataTable, but the WPF binding system seems to be complaining about the binding path I specify.

As an example, a GridViewColumn is defined as follows:

<GridViewColumn Header="ColumnTitle" DisplayMemberBinding="{Binding Path=/, Converter={StaticResource myConverter}}"/>

As far as I understand (and MSN seems to support me), specifying Path=/ should make the binding on the current item of the data collection.

The error I receive (in the trace window) is:

System.Windows.Data Error: 39 : BindingExpression path error: '' property not found on 'current item of collection' ''OrdersRow' (HashCode=680171)'. BindingExpression:Path=/; DataItem='OrdersRow' (HashCode=680171); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

This is giving me the impression that / isn't even a valid path, and WPF is expecting something after the slash. If so, how else would I bind to the current item? Why am I getting this error in the first place?

+3  A: 

Have you tried omitting the Path parameter?

<GridViewColumn Header="ColumnTitle"
     DisplayMemberBinding="{Binding Converter={StaticResource myConverter}}"/>
sixlettervariables
@sixlettervariables: Thanks for your reply. You are indeed correct about missing out the `Path` parameter. Sorry, but I had to give Martin the answer for the extra detail.
Noldorin
+2  A: 

I think the confusion is that the DataContext for the GridViewColumn is not the top collection, but is already the item that is bound to that column, so you don't need to specify a path.

The time that the you may use a path like this is if your control's DataContext is a List and you want to bind to the selected item. A possible example would be.

<Combobox DataContext={Binding ColourList}
          DataSource={Binding} <!--Bind to the datacontext -->
          ForeColor={Binding/} <!--Bind to the currently selected item in the datacontext -->
          />
Martin Harris
@Martin: Yeah, that's exactly where my confusion came from. I didn't even try leaving the path out becase I automatically thought this referred to the collection as a whole. Thanks for the full explanation.
Noldorin