Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Need a way of making one window aware of a change on a child window

$
0
0

We're working with VS 2015 and using MVVM Light. This is the first time we've really used MVVM Light, so I kind of doubt we're going strictly by the book. I say that up front so that you'll know this might be involved in the issue we're having.

We're required to write this WPF app that will have a launch window with buttons on it that the user will click. These buttons bring up a window with different portions of the data displayed, depending upon what the user clicked on. This is in a separate window, launched modelessly. To simplify things I'll focus upon just one area, called Grievances.

The Grievance window has data for grievances, plus a tab control with 2 tabitems, each with one datagrid on it. One for steps and another for face-to-face meetings. I'll focus just upon face-to-face meetings.

If the user double-clicks on a row in the face-to-face datagrid, then a modal window pops up, showing them the details about that particular face-to-face meeting. They may edit something here or delete the face-to-face meeting. If they edit the record, when they return to the Grievance window that record appears updated in the face-to-face datagrid. This behavior is as we want it. But I confess that neither I nor the guy working with me are entirely clear as to how it is updated, but we're glad it is.

If however, the user clicks on the Delete button on the modal window for the face-to-face meeting, it does delete the record from the table, but it doesn't update the face-to-face datagrid on the Grievance window. Is it obviously not what we want, but like I said we're not sure why it's not working as we'd hoped.

We're using MVVM Light's Messaging to send messages through the SimpleIoC container to launch windows.

I'm going to provide as much code as I think is involved. I'm hoping that it will be enough for you all to be able to see where we're going wrong or what we still need to do.

Here's the XAML for the datagrid from the Grievance window:

<DataGrid x:Name="GrvF2FMeetingGrid"
		  ItemsSource="{Binding Grv_F2FMeeting}"
		  IsReadOnly="True"
		  BorderThickness="1"
		  AutoGenerateColumns="False"
		  Grid.Column="1"
		  GridLinesVisibility="All"><i:Interaction.Triggers><!-- D01.04o double-clicking launches Meeting detail --><i:EventTrigger EventName="MouseDoubleClick"><cmd:EventToCommand Command="{Binding RelatedGrvF2FMeetingCommand}"
						PassEventArgsToCommand="True"
						CommandParameter="{Binding SelectedItem, ElementName=GrvF2FMeetingGrid}"/></i:EventTrigger></i:Interaction.Triggers><DataGrid.Columns><DataGridTextColumn Header="Date" Binding="{Binding MeetingDate, StringFormat=d}" /><DataGridTextColumn Header="Attendees" Binding="{Binding Attendees}" /><DataGridTextColumn Header="Notes" Binding="{Binding Notes}" /></DataGrid.Columns></DataGrid>

Grv_F2FMeeting is the table from the database, which we fetch with EF. And of course it is also a property in the VM. Here's its definition:

public Grv_F2FMeeting Grv_F2FMeeting
{
	get { return _grv_F2FMeeting; }
	set
	{
		_grv_F2FMeeting = value;
		//_template = LRAT.Common.CoreUtils.CloneEntityObject<Template>(value);
		RaisePropertyChanged("Grv_F2FMeeting");

		if (Grievance == null)
		{
			AssignGrievance();
			RefreshDataHander(_grv_F2FMeeting.GrievanceID);
		}
		else if (_grv_F2FMeeting != null && Grievance.GrievanceID != _grv_F2FMeeting.GrievanceID)
		{
			//I did this in an effort to try and not go back to the database as often.
			AssignGrievance();
		}
	}
}

AssignGrievance and RefreshDataHandler definitions:

private void AssignGrievance()
{
	Grievance grieve = App.MainDataContext.Grievances
		.Where(g => g.GrievanceID == _grv_F2FMeeting.GrievanceID)
		.FirstOrDefault();
	Grievance = grieve;
}

private void RefreshDataHander(long grievanceID)
{
	var f2fMeetings = App.MainDataContext.Grv_F2FMeeting.Where(f => f.GrievanceID == grievanceID).ToList();
	_dataHandler = new ViewModelDataHandler<Grv_F2FMeeting>(f2fMeetings);
	_dataHandler.CountInQuery = _dataHandler.CountInTable = f2fMeetings.Count;
}

I think I've covered everything. If I haven't or you need more to help us figure out what we're doing wrong, please let me know and I'll gladly share it.

Thank you.


Rod


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>