XAML Path Is Not Recognized

RogerSchlueter-7899 1,781 Reputation points
2026-08-07T10:42:45.7433333+00:00

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?

Developer technologies | Windows Presentation Foundation
0 comments No comments

2 answers

Sort by: Most helpful
  1. Tony Thach (WICLOUD CORPORATION) 845 Reputation points Microsoft External Staff Moderator
    2026-08-07T12:29:47.82+00:00

    Hello @RogerSchlueter-7899

    Thank you for your patience. I was able to reproduce the same binding error in a minimal WPF project:

    
    System.Windows.Data Error: 40 : BindingExpression path error:
    
    'CategoryID' property not found on 'object' ''String' (...)'.
    
    BindingExpression:Path=CategoryID;
    
    DataItem='String';
    
    target element is 'ComboBox' (Name='cbxCategories');
    
    target property is 'SelectedValue'
    
    

    I reproduced it using the same relevant XAML:

    
    <ComboBox x:Name="cbxCategories"
    
              Width="300"
    
              HorizontalAlignment="Left"
    
              DataContext="CurrentTransaction/Details.DefaultView"
    
              DisplayMemberPath="Name"
    
              SelectedValuePath="CategoryID"
    
              SelectedValue="{Binding Path=CategoryID,
    
                  diag:PresentationTraceSources.TraceLevel=High}" />
    
    

    The issue is indeed caused by this assignment:

    
    DataContext="CurrentTransaction/Details.DefaultView"
    
    

    This does not create a WPF binding. It assigns the literal string "CurrentTransaction/Details.DefaultView" to the DataContext property of the ComboBox.

    In XAML, a binding must be declared through the {Binding ...} markup extension (or its equivalent object-element syntax). Without a markup extension, an attribute value is generally processed as a literal string or converted from a string to the target property type. This behavior is described in the Microsoft documentation:

    The high-level binding trace confirms the actual runtime source:

    
    Activate with root item 'CurrentTransaction/Details.DefaultView'
    
    At level 0 - for String.CategoryID found accessor <null>
    
    

    Therefore, this binding:

    
    SelectedValue="{Binding Path=CategoryID}"
    
    

    is effectively asking WPF to find a CategoryID property on a System.String. Since System.String has no such property, WPF reports:

    
    DataItem='String'
    
    String.CategoryID found accessor <null>
    
    

    There is also a separate issue with the suggested path:

    
    {Binding CurrentTransaction/Details.DefaultView}
    
    

    CurrentTransaction and Details are sibling properties of the Transactions object; Details is not a property of CurrentTransaction.

    In addition, / does not mean normal property traversal in a WPF binding path. Microsoft documents / as collection-view current-item syntax. Normal property traversal uses a period (.), while / refers to the current item of a collection view.

    For example, Microsoft documents Path=/ as binding to the current item of a collection view. Therefore, simply changing the original value to:

    
    DataContext="{Binding CurrentTransaction/Details.DefaultView}"
    
    

    does not correctly express the relationship between the two sibling properties and does not provide the category rows to the ComboBox through its ItemsSource.

    Assuming the Window.DataContext is an instance of Transactions, the corrected binding is:

    <ComboBox x:Name="cbxCategories"
    
              ItemsSource="{Binding Details.DefaultView}"
    
              DisplayMemberPath="Name"
    
              HorizontalAlignment="Stretch"
    
              Margin="0,0,5,4"
    
              SelectedValuePath="CategoryID"
    
              SelectedValue="{Binding CurrentTransaction.CategoryID,
    
                                      Mode=TwoWay}" />
    

    Each binding property has a distinct role:

    • ItemsSource="{Binding Details.DefaultView}" supplies the category rows from the Details table.
    • DisplayMemberPath="Name" displays the Name column for each row.
    • SelectedValuePath="CategoryID" tells the ComboBox to use the selected row's CategoryID as its SelectedValue.
    • SelectedValue="{Binding CurrentTransaction.CategoryID, Mode=TwoWay}" reads the initial category from the current transaction and writes a newly selected category back to it.

    In the reproduced example, CurrentTransaction.CategoryID is initially 2, so the ComboBox correctly selects the row whose CategoryID is 2, which is Transport. Changing the selection also updates CurrentTransaction.CategoryID because the SelectedValue binding is two-way.

    The earlier AI suggestion did not work because it still used CurrentTransaction/Details.DefaultView as one path, even though CurrentTransaction and Details are sibling properties, and it assigned the supposed list source to DataContext instead of ItemsSource. In WPF, / refers to the current item of a collection view; it is not a general replacement for normal property traversal.

    Thank you again for your patience. Please let me know if the actual Transaction class or the DataTable setup differs from this structure.

    If my explanation and the information I provided were helpful, I would greatly appreciate it if you could follow the instruction here so others experiencing similar behavior can benefit from it as well. 

    Was this answer helpful?

    3 people found this answer helpful.

  2. AI answer

    2026-08-07T10:43:00.9766667+00:00

    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:

    1. CurrentTransaction/Details.DefaultView must be inside {Binding ...}.
    2. In WPF binding paths, / is used for source traversal in hierarchical data.
    3. 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:

    • Start debugging.
    • Open Debug > Windows > XAML Binding Failures.
    • Check the Data Context, Binding Path, and Description columns to see what object WPF is using for 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:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.