I am using a GridView in a master - detail, MVVM, Prism scenario. When I navigate to the master, I want to set the selected item to an item whose ID is passed in during navigation. The difficulty I am having is that appears that the Selected Item is being set in the modelview before the GridView data loading is complete. In debug, I can see that the Selected Item is getting set properly and PropertyChanged is raised for the operation. Subsequent to this, the Selected Item is getting reset to a different value from the GridView via the TwoWay binding, I'm guessing after data loading has been completed by the GridView. How can I ensure that the selection being made from within the viewmodel does not get overriden by the loading operation of the GridView? Here are some code snippets:
public void OnNavigatedTo(NavigationContext navigationContext){ // Called to initialize views during navigation. // Is this for AgentView? if (navigationContext.Uri.ToString().Contains("AgentsView")) { // The ID of the item to be displayed is passed as a navigation parameter. // ToInt32 can throw FormatException or OverflowException. try { int id = Convert.ToInt32(navigationContext.Parameters["PersonID"]); if (id == 0) return; // Retrieve the specified item using the data service. var agent = new DAL.Agent(); _agentsDataService.GetSelectedAgent(id, GetAgentsCallback); } catch (FormatException e) { //Console.WriteLine("Input string is not a sequence of digits."); //return CurrentItem == null ? false : CurrentItem.Id.Equals(id); } }}private void GetAgentsCallback(DAL.Agent agent){ _navigatedToAgent = agent; if (_navigatedToAgent != null) { SelectedAgent = _navigatedToAgent; }}public DAL.Agent SelectedAgent{ get { return _selectedAgent; } set { if (_selectedAgent == value) return; _selectedAgent = value; RaisePropertyChanged(() => SelectedAgent); _eventAggregator.GetEvent<AgentSelectedEvent>().Publish(_selectedAgent); }}SelectedItem="{Binding SelectedAgent, Mode=TwoWay}"