How to make a cell in a datagrid readonly based the content on another cell in SL4?
Posted
by
Nair
on Stack Overflow
See other posts from Stack Overflow
or by Nair
Published on 2011-02-12T23:22:09Z
Indexed on
2011/02/12
23:25 UTC
Read the original article
Hit count: 224
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?
© Stack Overflow or respective owner