Have a WPF Datagrid binded to a observablecollection, that it is getting populated from the database, which can be editable or non editable based on a value of a column value.
Now, would like to add a new row in the datagrid through a context menu click which is editable, although already existing rows would be non-editable (i.e., disabled).
Well this can be achievable using a data trigger on the column value and defining a converter on the binded value i.e., selectedItem to the row. Now, problem is when I add new row, my command param passed is the selectedItem i.e.,
Menu Item Code:
MenuItem Header="Add" Command="{Binding AddClickCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.SelectedItem}"
So, this is the existing row (i.e., row 1) on which I clicked to add new row(row 2), so, I get the context of the existing row (i.e., row 1).
Can anybody help me get the context of the new row added i.e., row 2 through which I can set the certain flags to enable that row as editable!
if you wanna add a new row to your datagrid why not simply create a add command where you add a new item to your ObservableCollection and set this new item to your selectedItem, so its selected in your datagrid.
private void AddCommandExecute()
{
var toAdd = new MyItem();//new "row item"
this.MyCollection.Add(toAdd);//add to collection with automatic notification
this.MySelectedItem = toAdd;//set as selected
}