5

When to use "/" symbol in path? I thought "/" uses only when we work with XML, but today see example:

class ViewModel
{
    CollectionView Data {get;set;}
}

class BusinessObkect
{
    string Name {get;set;}
}

DataContext property of the window is set to an instance of the ViewModel class, Data property of the ViewModel instance is niitialized with a collection of BusinessObject objects.

if Text property of TextBox instance {Binding Path=Data/Name} all works normal, but if Text = {Binding Path=Data.Name} - binding error.

When I must use "/" instead of "." in bindings Path?

2 Answers 2

13

Why not ask the documentation:

Subproperties of a property can be specified by a syntax similar to that used in C#. For instance, the clause Path=ShoppingCart.Order sets the binding to the subproperty Order of the object or property ShoppingCart.

When the source is a collection view, the current item can be specified with a slash (/). For example, the clause Path=/ sets the binding to the current item in the view. When the source is a collection, this syntax specifies the current item of the default collection view.

(Collection view link added for convenience)

That's about as concise and complete as it gets. Using . notation with a collection to a property of one of its items does not even make sense. e.g. Collection.Date as opposed to Collection/Date (unless the collection itself actually has a Date property for some reason).

Sign up to request clarification or add additional context in comments.

Comments

4

You need to use it when Data is a collection. / takes the current element of the Data collection and returns the Name property on it.

2 Comments

What do you mean by the "current element of [a] collection"? None of the collection types that I am familiar with have a concept of a current item in and of themselves.
In this case, he uses a CollectionView on its own, it already has that. If you use an ObservableCollection<T> (or similar), the WPF engine wraps it into a CollectionView to supply this necessary infrastructure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.