Wpf DataGridTextColumn具有元素样式和ReadOnly

时间:2015-10-22 09:14:19

标签: wpf datagridtextcolumn

我需要根据触发器禁用特定列的编辑,但不起作用。

<DataGridTextColumn Binding="{Binding Qty,UpdateSourceTrigger=PropertyChanged}" Header="QTY" Width="100">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="HorizontalAlignment"  Value="Right"></Setter>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ItemType}" Value="Discount">
                                    <Setter Property="IsEnabled" Value="False"></Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

1 个答案:

答案 0 :(得分:0)

添加:

<DataGridTextColumn.EditingElementStyle>
    <Style TargetType="TextBox">
        <Setter Property="HorizontalAlignment"  Value="Right"></Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding ItemType}" Value="Discount">
                <Setter Property="IsEnabled" Value="False"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGridTextColumn.EditingElementStyle>