是否可以使用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>发布于 2017-09-05 21:29:44
试试这个:
<DataGridTextColumn IsReadOnly="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.IsReadOnlyProperty}" />创建DataGrid时,可以通过分配ItemsSource来设置其DataContext。这将限制DataGrid内的所有控件仅使用其父DataContext中的对象,因此,如果要绑定到此DataContext外部的属性,则必须显式声明要更改作用域。
https://stackoverflow.com/questions/11755760
复制相似问题