Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Binding syntax

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?

like image 239
Dmitriy Kudinov Avatar asked Jun 20 '11 16:06

Dmitriy Kudinov


1 Answers

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).

like image 69
H.B. Avatar answered Sep 20 '22 05:09

H.B.