【发布时间】:2010-11-10 17:11:59
【问题描述】:
我已经使用 MEF 加载外部 XAP,效果很好。 但是,当我离开加载了控件的页面,然后返回到该页面时,该控件处于我离开它的确切状态。
现在有时这很好,但不适用于我正在从事的项目。
如何将控件重置为其初始状态?
控件被加载(成功)到这里:
<ItemsControl x:Name="content"/>
这是在 XAML 标记中
我有一个 On NavigatedFrom 方法:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
content.Items.Clear();
}
这成功删除了控件,就像在添加之前一样,当我返回页面时它崩溃了,告诉我控件已经是元素的子元素。
这是完整的页面代码:
public partial class Wizard : IPartImportsSatisfiedNotification
{
public Wizard()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
var controlToLoad = IsolatedStorageHelper.GetValue("control");
if (!String.IsNullOrEmpty(controlToLoad))
{
CatalogService.AddXap(controlToLoad + ".xap");
}
else
{
NavigationService.Navigate(new Uri("/ServiceSelector", UriKind.Relative));
}
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
content.Items.Clear();
}
[Import]
public IDeploymentCatalogService CatalogService { get; set; }
[ImportMany(AllowRecomposition = true)]
public Lazy<UserControl>[] MefModuleList { get; set; }
#region IPartImportsSatisfiedNotification Members
public void OnImportsSatisfied()
{
MefModuleList.ToList()
.ForEach(module =>
content.Items.Add(module.Value)
);
}
#endregion
}
有人有什么想法吗?
谢谢,
【问题讨论】:
标签: c# silverlight-4.0 mef