A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
We are currently investigating the issue and will provide an update soon. Thank you for your patience.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am working with a Transactions class:
Public Class Transactions
....
Public Property CurrentTransaction As Transaction
Public Property Details as DataTable
End Class
The Details table has a "CategoryID" column. In the wpf for a Transaction I have:
<Window
....
<ComboBox
x:Name="cbxCategories"
DataContext="CurrentTransaction/Details.DefaultView"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch"
Margin="0,0,5,4"
SelectedValue="{Binding Path=CategoryID}"
SelectedValuePath="CategoryID" />
....
</Window>
This gives a run-time error:
BindingExpression path error: 'CategoryID' property not found on 'object' ....
What is wrong with my binding?
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
We are currently investigating the issue and will provide an update soon. Thank you for your patience.
AI answer
Path=CategoryID is being resolved against the current binding source, and that source is not the row/view object that exposes CategoryID.
The main issue is this line:
DataContext="CurrentTransaction/Details.DefaultView"
That sets a literal string, not a binding expression. In WPF, property paths for data binding must be used through a binding, for example Path="propertyName/propertyNameX" when traversing a hierarchy.
Use a real binding for the source, for example:
<ComboBox
x:Name="cbxCategories"
DataContext="{Binding CurrentTransaction/Details.DefaultView}"
DisplayMemberPath="Name"
HorizontalAlignment="Stretch"
Margin="0,0,5,4"
SelectedValue="{Binding CategoryID}"
SelectedValuePath="CategoryID" />
Key points:
CurrentTransaction/Details.DefaultView must be inside {Binding ...}./ is used for source traversal in hierarchical data.SelectedValue="{Binding CategoryID}" only works if the DataContext is an item that actually has a CategoryID property/column.If the error continues, inspect the actual runtime binding source in Visual Studio:
CategoryID.That will show whether the ComboBox is bound to the expected row/view object or to some other object that does not contain CategoryID.
References: