我有一个
在VS输出窗口中,我收到以下错误信息:
我认为问题出在如何指定
ComboBox
,它包含一个DataTemplate
,我想将其IsEnabled
属性绑定到模板DataGridTemplateColumn
上的IsReadOnly
属性,但遇到了问题。在VS输出窗口中,我收到以下错误信息:
ComboBox样式:'IsReadOnly'属性在'object''ContentPresenter'上未找到
<Style TargetType="{x:Type ComboBox}" x:Key="ProficiencyColumnComboBoxStyle">
<Setter Property="IsEnabled"
Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
Path=IsReadOnly, Converter={StaticResource BooleanOppositeConverter}}" />
</Style>
我认为问题出在如何指定
DataGridColumn
的RelativeSource
上。我尝试过以下方式:
RelativeSource={RelativeSource TemplatedParent}
RelativeSource AncestorType={x:Type DataGridColumn}
RelativeSource AncestorType={x:Type DataGridTemplateColumn}
DataTemplate
已经被应用到控件上。
P.S.
我曾使用同样的技术将DataTemplate
中的另一个ComboBox
绑定到父级DataGrid
的模板列属性。不同之处在于,这里我使用了转换器,并尝试将其绑定到列的属性(而不是网格)。但是,即使我从上面的样式中删除转换器,也没有进行任何绑定。
Binding.Source
与x:Reference
结合来绑定 DG 列,可能会出现循环依赖的复杂情况。 - H.B.