开发者

Silverlight DataGrid set cell IsReadOnly programmatically

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?


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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜