That is simple as you can pass the parameter to the other page in query string by using the following method in an event handler (edit_ButtonClick) shown below:
private void NavigateToEditEvent(string eanCode)
{
NavigationService.Navigate(new Uri("/EditProduct?EANCode=" + eanCode, UriKind.Relative));
}
private void editButton_Click(object sender, RoutedEventArgs e)
{
Product product = productDataGrid.SelectedItem as Product;
if (product != null)
{
NavigateToEditEvent(product.EANCode);
}
}
In the edit page do the following:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string eanCode = NavigationContext.QueryString["EANCode"];
productDomainDataSource.FilterDescriptors.Add(
new FilterDescriptor ( "EANCode", FilterOperator.IsEqualTo, eanCode ) );
}
The problem is you don't want to select a row and then click a button. I have used "datagrid_IsEditing" event successfully. But it has some behavioural issue.
You need to have a new datacontext. set it to current record by using the value in the query string and then try to save it using submit changes.
Another option would be to use dataform and datafields.
Both options throw exceptions, even though they are working on a different datacontext.
I am retrying those options today after a while and I need it fixed. Any help would be appreciated.