In the main onClick window I have
AddNoticeAboutWrongCity addNoticeAboutWrongCity = new AddNoticeAboutWrongCity(); addNoticeAboutWrongCity.DataContext = ((VerificationViewModule)this.DataContext).WrongCityNotice; addNoticeAboutWrongCity.ShowDialog();
There are many text and two buttons in the popup
Delete item:
this.DataContext = null;
And the second option is “Save edited notification”, which cannot be used, since every change in the user attachment of the datacontext is in the main window, and this is required from the design department :)
I do not know why the first option (this "implementation" does not work.
The second explanation:
In ParentWindow, I have a list of notifications and I can click EditSelectedNotice.
In EditNoticeWindow, I can edit the notification or delete the notification.
Editing works (after closing EditNoticeWindow I see a modified notification in ParentWindow), but the deletion fails (the notification is still in the collection - on the control and in this .DataContext)
My ViewModel:
class VerificationViewModule { public ObservableCollection<ReporterNotice> ReporterNotices { get; set; } public ReporterNotice OtherNotice { get { return ReporterNotices.Where(n => n.Type == ReporterNoticeType.Other).FirstOrDefault(); } } public ReporterNotice DuplicateNotice { get { return ReporterNotices.Where(n => n.Type == ReporterNoticeType.Duplicate).FirstOrDefault(); } } public ReporterNotice WrongCityNotice { get { return ReporterNotices.Where(n => n.Type == ReporterNoticeType.WrongCity).FirstOrDefault(); } set { if(value==null) { ReporterNotices.Remove(ReporterNotices.Where(n => n.Type == ReporterNoticeType.WrongCity).First()); } else { if (ReporterNotices.Where(n => n.Type == ReporterNoticeType.WrongCity).FirstOrDefault()==null)
source share