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?
You should write
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.Countevaluates to the value of the property itself, not the object that exposes it.