as far as we know the property ‘CanUserAddRows ‘ can be used in datagrid to give user limitation to add new rows or not.
the detail about this property is described in https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.datagrid.canuseraddrows?view=windowsdesktop-8.0
if we set CanUserAddRows = false ,the user can not add new rows and input data , if we set true, it means the row can be generated automaticlly
But some times we would like to binding one property to ‘CanUserAddRows ‘ to make row adding dynamically, for example ,we would like to user can add rows but the max number of rows can not be above 10. maybe we will implement like this
public bool CanUserAddRow => Persons.Count < 10;

it seems the solution is perfect . but it does not work.
The reason is that if we would like to binding one property to ‘CanUserAddRow' the binding mode must be ‘TwoWay’, So when we defined the property , we can not defined one readonly property to binding ,we should define the property like this

and in xaml we will binding this property

then it works.
Leave a comment