3
Reply

[WPF] DataGrid Read Only but not for new row

Roberto Salemi

Roberto Salemi

Apr 17 2015 9:11 AM
1.6k
Hi,
I have a DataGrid (called dgSample), where I set IsReadOnly="True".

User can add a new Row, this row must be editable.

So in my model I set a property:
[DefaultValue(false)]
public virtual bool IsNewItem { get; set; }

where user add new row I set this property to true

So in my DataGrid I have:
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsNewItem}" Value="True">
<Setter Property="IsReadOnly" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>

but the last Row is not editable, why?

Thanks.

Answers (3)