【发布时间】:2012-08-01 08:51:24
【问题描述】:
我可以使用 elementStyle 将 DatagridTextColumn IsReadOnly 绑定到 ViewModel 内的属性(此处为 IsReadOnlyProperty)吗? 像这样:
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="IsEnabled" Value="{Binding IsReadOnlyProperty}"/>
</Style>
</DataGridTextColumn.ElementStyle>
<DataGridTextColumn.EditingElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="IsEnabled" Value="{Binding IsReadOnlyProperty}" />
</Style>
</DataGridTextColumn.EditingElementStyle>
【问题讨论】:
-
确定我做到了!!它没有绑定!!
-
IsReadOnlyProperty 不在 datagrid Itemsource 中,它被放置在 ViewModel 中。
-
@raha:您的 ItemsSource 应该是视图模型的集合,那么在哪个上下文中可以访问该视图模型?
-
但它有效!!视图模型在窗口上下文中!
标签: wpf wpfdatagrid datagridtextcolumn