I am doing something like this in a Silverlight 3 datagrid:
for (int x = 0; x < ThisForecast.Periods.Count; x++)
{
var TextColumn = new DataGridTextColumn();
TextColumn.Header = ThisForecast.Periods[x].Name;
TextColumn.Binding = new Binding(String.Format("Periods[{0}].Quantity", x));
TextColumn.Binding.Mode = BindingMode.TwoWay;
TextColumn.IsReadOnly = false;
dgItemForecast.Columns.Add(TextColumn);
}
And it works great, but I want to change the ready only to something more like: TextColumn.IsReadOnly = new Binding(String.Format("Periods[{0}].IsReadOnly", x));
And while it seems easy to do in XAML, I can't figure out the correct method to do this in the code behind. Obviously I can't set it to a 'binding', but where would I be able to set something like that?
EDIT #1:
I looked at the BindingOperations.SetBinding()
given below, but could not find a DependencyProperty
for IsReadOnly. Is there a way to inject/add one?