I have a DataGrid with 4 columns, the first two of them are bound to an object.
The other two are button columns are made like this
<DataGridTemplateColumn MaxWidth="100" Header="Delete">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="BtnDelete" CommandParameter="{Binding Path=Id}" Content="Delete" Click="BtnDeleteEmployee_Click" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
My Datagrid has CanUserAddRows=”True” which always generates an empty row in the bottom of the grid.
However, I would like the two buttons on the bottom row to be disabled until the other rows have been filled. As it is now, I’m (of course) getting a nullreferenceexception when I click the button.
I guess a solution would be to bind the button’s IsEnabled property to
id>0
But how to do this, I am not sure.
One way to accomplish this is to bind the
IsEnabledproperty to the Id property and use a ValueConverter to retun True or False based on your criteria.A value converter could look like this:
and you reference it in your resources section:
And bind the
IsEnabledproperty: