PRISM RegionManager - ItemsControl RegionManager 的非 XAML 创建
我对 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 附加到 Control 之外,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());
感谢您的任何提示...
I have a small problem with Regions in PRISM. All basics tests work fine, but now I want to replace the following XAML with pure C#:
<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>
The code inside my testing class is fairly simple, I access the RegionManager and add some test views. However, as you see in the XAML above, there is actual nothing happening in the UserControl except from attaching the RegionManager to the Control. I am sure this must be possible in Code, extending the following lines I already have:
// 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());
Thanks for any tips...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,XamlReader 方法正在工作(一些修正,请参阅随附的源代码)...
但说实话,它看起来有点难看:-)
因此,如果有人知道如何“在代码中附加区域管理器”,欢迎详细信息。
首先,有效的 XAML 读取器行是:
明白了! (至少它有效,不确定是否是最佳实践)
感谢所有帮助...仍然欢迎评论...
Ok, the XamlReader Approach is working (little corrections, see source code attached)...
But honestly, it looks a little bit ugly :-)
So if anybody knows how to "attach the regionManager in Code", details are welcome.
First, the working XAML reader lines are:
GOT IT!! (at least it is working, not sure if best practice)
Thanks for all help... Comments still welcome...
尝试 XamlReader 方法:
Try the XamlReader approach: