【问题标题】:OneWay binding throws "TwoWay binding is invalid on Read only property"单向绑定抛出“只读属性上的双向绑定无效”
【发布时间】:2011-02-20 15:27:21
【问题描述】:

这个绑定

<tk:DataGridTextColumn Binding="{Binding Path=Id, Mode=OneWay}" 
Header="Sale No." Width="1*" />

给出这个错误

TwoWay 或 OneWayToSource 绑定 不能在只读属性上工作 'Id' 类型。 . .

“Id”属性确实是只读的,但我认为Mode=OneWay 就足够了。

我很累,我知道我遗漏了一些明显的东西,所以我现在很抱歉问了一个非常愚蠢的问题。

谢谢
体重

【问题讨论】:

    标签: wpf data-binding xaml


    【解决方案1】:

    如果我没记错的话,我认为 DataGridTextColumn 在生成编辑元素时会踩到您的 Binding.Mode,因为如果 DataGrid 是可编辑的,列本身仍默认为读/写。尝试在 DataGridTextColumn 上设置 IsReadOnly="true"。

    【讨论】:

    • 您是绅士先生,也是人中的王子!我寻找了一个“只读”属性,但仍然不了解 WPF 正确命名的属性。谢谢一百万乔希:)
    猜你喜欢
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 2012-12-17
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多