【发布时间】:2011-03-11 21:51:16
【问题描述】:
在主窗口上点击我有
AddNoticeAboutWrongCity addNoticeAboutWrongCity = new AddNoticeAboutWrongCity();
addNoticeAboutWrongCity.DataContext = ((VerificationViewModule)this.DataContext).WrongCityNotice;
addNoticeAboutWrongCity.ShowDialog();
在弹出窗口有很多文本框和两个按钮
删除对象:
this.DataContext = null;
第二个选项“保存编辑的通知”不可用,因为主窗口上的用户情感数据上下文的每次更改,这是设计部门的要求:)
我不知道为什么第一个选项(它的“实施”不起作用。
第二个解释:
在 ParentWindow 我有通知列表,我可以单击 EditSelectedNotice。
在 EditNoticeWindow 我可以编辑通知或删除通知。
Editinig 有效(关闭 EditNoticeWindow 后,我在 ParentWindow 上看到更改的通知),但删除没有(通知仍在收集中 - 在控件和 this.DataContext 中)
我的视图模型:
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)//there is always only max one instance of this type of notice
{
ReporterNotices.Add(value);
}
else
{
var c = ReporterNotices.Where(n => n.Type == ReporterNoticeType.WrongCity).First();
c = value;
}
}}
}
public VerificationViewModule()
{
ObservableCollection<ReporterNotice> loadedReporterNotices = new ObservableCollection<ReporterNotice>();
loadedReporterNotices.Add(new ReporterNotice() { Content = "Dublic", Type = ReporterNoticeType.WrongCity });
loadedReporterNotices.Add(new ReporterNotice() { Content = "Hilton", Type = ReporterNoticeType.Duplicate });
loadedReporterNotices.Add(new ReporterNotice() { Content = "Another notice", Type = ReporterNoticeType.Other });
ReporterNotices = loadedReporterNotices;
}
}
【问题讨论】:
-
抱歉,我不太确定你想做什么,什么不起作用,你能详细说明一下吗?
-
在 ParentWindow 我有通知列表,我可以单击 EditSelectedNotice。在 EditNoticeWindow 我可以编辑通知或删除通知。编辑有效,但删除无效。
标签: c# wpf mvvm .net-3.5 datacontext