How to make a cell in a datagrid readonly based the content on another cell in SL4?

感情迁移 提交于 2019-12-13 03:37:59

问题


I have two columns, the second column depends on the content on the first column. By default, the second columns is readonly. When I enter some valid value, I want the second column to become editable. To achive this, I created a cell template and cell edit template on the second column where back ground and read only bound to the first column. On load, the first column is null so my second columns comes correctly as read only. Following is Cell Template for second column, where the background color is set by based on the first column.

 <DataTemplate>
   <Grid>
     <Border Background="{Binding FristColumn,Converter={StaticResource ColorConverter}}"/>
     <TextBlock Text="{Binding SecondColumn, Converter={StaticResource NumberFormatter}}" HorizontalAlignment="Stretch"  VerticalAlignment="Center" Margin="0"/>
   </Grid>
  </DataTemplate>

Following is cell edit template for second column to make it editable

<DataTemplate>
  <Grid>
    <TextBox Text="{Binding SecondColumn, Mode=TwoWay, Converter={StaticResource NumberFormatter}}" Margin="0" HorizontalAlignment="Right"  IsReadOnly="{Binding FirstColumn, Converter={StaticResource readOnlyConverter}, ConverterParameter=FirstColumn}" Background="{Binding Depend,Converter={StaticResource ColorConverter}, ConverterParameter=FirstColumn}" />
  </Grid>
</DataTemplate>

With these two in place, when enter the valid value in the first column, I was expecting the second column color to change but it does not. But If I double click on the cell then it behaves properly based on the first cell. Is there some thing I am missing?


回答1:


The problem was, the object collection did not have INotifyPropertyChanged implemented. Once I have INotifyPropertyChanged implemented, the colors and cell become editable and non editable based on the converter. Hope this helps others.



来源:https://stackoverflow.com/questions/4981291/how-to-make-a-cell-in-a-datagrid-readonly-based-the-content-on-another-cell-in-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!