Reputation: 550
I'm making a simple project in Silverlight. It contains a ListBox and a Label. I tried to bind listbox.Items.Count property to Label.Content property so I can see amount of items which are currently present on it. I've used this link as a support and information source.
Binding myBinding = new Binding("CountProperty");
// columnNameList - listbox
myBinding.Source = this.columnNamesList.Items.Count;
// columnCount - label
this.columnCount.SetBinding(Label.ContentProperty, myBinding);
It does not work for some reason. Any pointers?
Upvotes: 1
Views: 615
Reputation: 437544
You should write
var myBinding = new Binding("Count"); // no "Property" suffix
myBinding.Source = this.columnNamesList.Items; // object that has the property "Count"
First off, the name of the property in the example you cite is actually supposed to include the suffix "Property". In this case the name of the property is simply "Count", so you have to make the binding reflect that.
Second, the binding source always is the object that exposes the property with that name. In your initial code, this.columnNamesList.Items.Count
evaluates to the value of the property itself, not the object that exposes it.
Upvotes: 2