views:

353

answers:

2

I am binding a data grid to a collection of Task objects. A particular column needs some special rules pertaining to editing:

<!--Percent Complete-->
<data:DataGridTextColumn Header="%" 
                         ElementStyle="{StaticResource RightAlignStyle}" 
                         Binding="{Binding PercentComplete, Mode=TwoWay, Converter={StaticResource PercentConverter}}" />

What I want to do is set the IsReadOnly property only for each task's percent complete cell based on a property on the actual Task object. I've tried this:

<!--Percent Complete-->
<data:DataGridTextColumn Header="%" 
                         ElementStyle="{StaticResource RightAlignStyle}" 
                         Binding="{Binding PercentComplete, Mode=TwoWay, Converter={StaticResource PercentConverter}}"
                         IsReadOnly={Binding IsNotLocalID} />

but apparently you can't bind to the IsReadOnly property on a data grid column. What is the best way do to do what I am trying to do?

A: 

It looks like the DataGridColumn.IsReadOnly Property is a DependencyProperty so it should be bindable. Change your XAML to IsReadOnly="{Binding IsNotLocalID}" (Note the added quotes) and see what happens. Are you getting any binding failures in the Visual Studio output window?

DaveB
Ah, I'm on Silverlight 3, not Silverlight 4.
Brandon Montgomery
DataGrid is quite an old codebase as Silverlight goes, and many of its properties are not dependency properties. In particular, IsReadOnly on the DataGridBoundColumn base class is not a dependency property. I have this on good authority from the program manager for DataGrid. I've also directly asked him when the codebase will be updated and he declined to comment.
Peter Wone
+2  A: 

I don't think that you can Bind directly to this. I have found this extended DataGrid for Silverlight which will do the trick though.

Extended DataGrid

Ardman