达网络v4的DataGridTextColumn.IsReadOnly似乎是有故障 [英] .Net v4 DataGridTextColumn.IsReadOnly seems to be faulty

查看:291
本文介绍了达网络v4的DataGridTextColumn.IsReadOnly似乎是有故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我创建一个绑定的 DataGridTextColumn ,它不actualize的的IsReadOnly 属性。如果我通过标记设置它,它的工作原理。

If I create a binding to the IsReadOnly property of the DataGridTextColumn, it does not actualize. If I set it through markup, it works.

<DataGridTextColumn IsReadOnly="{Binding IsReferenceInactive}"/> <!-- NOP --> 

<DataGridTextColumn IsReadOnly="True"/> <!-- Works as expected, cell is r/o -->

IsReferenceInactive 属性是一个DP和工作正常(出于测试目的,我将它绑定到一个复选框,该工作)

The IsReferenceInactive property is a DP and works fine (For testing purposes I've bound it to a checkbox, that worked)

这是一个已知的限制?

更新

UUPS,其他比我写的,有在输出窗口消息:

Uups, other than I wrote, there is a message in the output window:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=IsReferenceInactive; DataItem=null; target element is 'DataGridTextColumn' (HashCode=23836176); target property is 'IsReadOnly' (type 'Boolean')

好像是这样:

Seems to be this one:

<一个href="http://connect.microsoft.com/VisualStudio/feedback/details/530280/wpf-4-vs2010-datagrid-isreadonly-does-not-work-with-binding-to-boolean-property">http://connect.microsoft.com/VisualStudio/feedback/details/530280/wpf-4-vs2010-datagrid-isreadonly-does-not-work-with-binding-to-boolean-property

推荐答案

的DataGridColumn 是不是可视化树的一部分,不参加这样的结合。我周围的获得方法是使用 DataGridTemplateColumn

DataGridColumns are not part of the visual tree, and don't participate in binding like this. The way I get around it is to use DataGridTemplateColumn.

<DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=myProperty}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox IsEnabled="{Binding Path=myBool}" Text="{Binding Path=myProperty Mode=TwoWay}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>

有其他的处理方法是,我发现有点太hackish的,但他们做的工作;即:<一href="http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx">http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx

There are other workarounds, which I've found a bit too hackish, but they do work; to wit: http://blogs.msdn.com/b/jaimer/archive/2008/11/22/forwarding-the-datagrid-s-datacontext-to-its-columns.aspx

这篇关于达网络v4的DataGridTextColumn.IsReadOnly似乎是有故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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