值转换器和 WPF DataGrid

发布于 2024-12-19 05:17:33 字数 623 浏览 3 评论 0原文

我在 wpf 中有一个数据网格,我的单元格

                    <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="Background" Value="{Binding  Value, Converter={StaticResource BinaryGridConverter}, ConverterParameter=1 }"/>
                    </Style>
                </DataGridTextColumn.CellStyle>

一切正常,唯一担心的是转换器不会在选定的单元格上触发。我的问题将更有意义与我的网格的屏幕截图,

当我右键单击任何单元格时,会出现上下文菜单,允许它会将单元格变成绿色,禁止它会将单元格通过转换器变成红色。

我有一个按钮,单击后我需要通过与依赖属性的绑定将网格带回其原始位置。问题是当我更改属性值时,转换器不会为每个单元格触发,它只会为那些未被我修改的单元格触发。

I have a datagrid in wpf, my cell is

                    <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="Background" Value="{Binding  Value, Converter={StaticResource BinaryGridConverter}, ConverterParameter=1 }"/>
                    </Style>
                </DataGridTextColumn.CellStyle>

Everything works fine, the only concern is the converter does not fire on selected cells. My problem will make more sense with the screenshot of my grid,

when i right click on any cell a context menu appear, on allow it will turn the cell green and on disallow it will turn the cell red through the converter.

i have a button, upon click i need to bring the grid back to its original position, through the binding with the dependencyproperty. The issue is when i change the property value the converter does not fire for every cell, it fires for only those cells that are not modified by me.

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

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

发布评论

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

评论(1

抱猫软卧 2024-12-26 05:17:33

问题是当我更改属性值时转换器没有更改
为每个细胞激发,只为那些不激发的细胞激发
由我修改。

没有足够的代码来准确,但从你的话来看,听起来像是你在代码中的某处手动设置了单元格背景值,这样你就打破了绑定

仔细检查是否使用绑定通过依赖属性更改单元格背景,而不是直接更改。

The issue is when i change the property value the converter does not
fire for every cell, it fires for only those cells that are not
modified by me.

There is not enough code to be exact, but from your words, it sounds like you set the cell background value manually somewhere in your code, and this way you break the binding.

Double check that you change the cell background through the dependency property using the binding, and not directly.

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