如何根据 SL4 中另一个单元格的内容使数据网格中的单元格只读?

发布于 2024-10-17 15:49:17 字数 1119 浏览 1 评论 0原文

我有两列,第二列取决于第一列的内容。默认情况下,第二列是只读的。当我输入一些有效值时,我希望第二列变得可编辑。 为了实现这一目标,我在第二列上创建了一个单元格模板和单元格编辑模板,其中背景和只读绑定到第一列。加载时,第一列为空,因此我的第二列正确地为只读。以下是第二列的单元格模板,其中背景颜色是根据第一列设置的。

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

以下是第二列的单元格编辑模板,使其可编辑。

<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>

有了这两个模板,当在第一列中输入有效值时,我期望第二列颜色发生变化,但事实并非如此。但是,如果我双击该单元格,那么它会根据第一个单元格正常运行。我缺少什么吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2024-10-24 15:49:17

问题是,对象集合没有实现 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文