基于SL4中另一个单元格的内容,如何使datagrid中的单元格按原样生成? [英] How to make a cell in a datagrid readonly based the content on another cell in SL4?

查看:89
本文介绍了基于SL4中另一个单元格的内容,如何使datagrid中的单元格按原样生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两列,第二列取决于第一列的内容。默认情况下,第二列是只读的。当我输入一些有效的值时,我想让第二列变为可编辑。
为了解决这个问题,我在第二列创建了一个单元格模板和单元格编辑模板,其后面和只读绑定到第一列。加载时,第一列为null,所以我的第二列正确地作为只读。以下是第二列的单元格模板,其中基于第一列设置背景颜色。

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?

推荐答案

问题是,对象集合没有实现INotifyPropertyChanged。一旦我有INotifyPropertyChanged实现,颜色和单元格可以编辑和不可编辑的转换器。
希望能帮助别人。

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.

这篇关于基于SL4中另一个单元格的内容,如何使datagrid中的单元格按原样生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆