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?
Have you tried omitting the Path parameter?
<GridViewColumn Header="ColumnTitle"
DisplayMemberBinding="{Binding Converter={StaticResource myConverter}}"/>
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 -->
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With