[英]Unregister a PRISM Region from the RegionManager
有沒有一種方法可以從RegionManager取消注冊區域?
用
RegionManager.SetRegionName(myRegion, regionName);
RegionManager.SetRegionManager(myRegion, myRegionManager);
我確實在RegionManager上注冊了一個區域。
但是,如果我需要刪除該注冊(以便再次注冊完全相同的區域),該怎么辦?
===================
這是我的情況:
我有一個實例myView
,它使用以下方法將UI控件(DependencyObject) myRegion
為區域:
RegionManager.SetRegionName(myRegion, regionName);
RegionManager.SetRegionManager(myRegion, myRegionManager);
實例化myView
,本地實例管理器對象myRegionManager
也被實例化。
然后,我需要再次創建實例myView
,該實例再次進行此注冊。
因此,新實例myView
也實例化了新的本地區域管理器myRegionManager
,該區域管理器當然沒有與之關聯的區域。
然后,對RegionManager.SetRegionName(...)
和RegionManager.SetRegionManager(...)
的調用成功,但是如果我嘗試使用以下方法訪問本地區域管理器myRegionManager
IRegion region = myRegionManager.Regions[regionName];
我正在收到RegionUpdateException
!
如果我放
string name = RegionManager.GetRegionName(myRegion);
IRegionManager regionManager = RegionManager.GetRegionManager(myRegion);
在注冊之前,兩個字段在myView
的第一個實例化之前都是空的,但是在myView
的第二個實例化期間它們確實具有值。
但是由於myRegion
和myRegionManager
也會與myView
一起被新實例化, myView
我希望名稱和區域管理器在調用第二個注冊之前也為空。
您可以使用RegionManager
的Regions
-Property按名稱刪除區域:
public interface IRegionManager
{
/// <summary>
/// Gets a collection of <see cref="IRegion"/> that identify each region by name. You can use this collection to add or remove regions to the current region manager.
/// </summary>
IRegionCollection Regions { get; }
[...]
}
和
public interface IRegionCollection : IEnumerable<IRegion>, INotifyCollectionChanged
{
[...]
/// <summary>
/// Removes a <see cref="IRegion"/> from the collection.
/// </summary>
/// <param name="regionName">Name of the region to be removed.</param>
/// <returns><see langword="true"/> if the region was removed from the collection, otherwise <see langword="false"/>.</returns>
bool Remove(string regionName);
[...]
}
根據您的描述,聽起來您需要具有一個已定義區域的同一個View的多個實例,並能夠將其他視圖插入這些相應的區域內。 這個對嗎?
請查看ScopedRegions上的文檔: https : //github.com/PrismLibrary/Prism/blob/master/Documentation/WPF/50-ComposedtheUserInterface.md#creating-multiple-instances-of-a-region
您還可以觀看此Pluralsight課程,該課程向您展示如何使用ScopedRegions: https ://app.pluralsight.com/library/courses/prism-showing-multiple-shells/table-of-contents
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.