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