我对 PRISM 中的区域有一个小问题。所有基础测试都可以正常工作,但现在我想用纯 C# 替换以下 XAML:
<UserControl x:Class="CAL.Modules.Simple.Region_Testing.RegionManagerTypes.XAML.ItemsControlRegionAdapterTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
Height="Auto" Width="Auto">
<ItemsControl cal:RegionManager.RegionName="ItemsControlRegionAdapterTestRegion"/>
</UserControl>
我的测试类中的代码相当简单,我访问 RegionManager 并添加一些测试视图。但是,正如您在上面的 XAML 中看到的那样,除了将 RegionManager 附加到控件之外,UserControl 中实际上没有发生任何事情。我确信这在代码中必须是可能的,扩展了我已经拥有的以下几行:
// MISSING
// Creating the UserControl in CODE instead of XAML
// Create the UserControl and add it to the main window
regionManager.AddToRegion(RegionNames.MainRegion, new ItemsControlRegionAdapterTest());
// Add some views to the region inside the user control
var currentTestRegionName = TestingRegionNames.ItemsControlRegionAdapterTestRegion;
regionManager.Regions[currentTestRegionName].Add(new BlueView());
regionManager.Regions[currentTestRegionName].Add(new RedView());
感谢您的任何提示...