为什么 ItemsControl 显示视图但 ContentControl 什么也不显示?
我有一个基于 Prism 的应用程序。
这是我的 shell:
<Window x:Class="AvarioCRM3.ShellV2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF" >
<DockPanel LastChildFill="True">
<Border
Padding="10"
DockPanel.Dock="Top"
Background="#ddd">
<DockPanel>
<ItemsControl
Name="MainNavigationPanel"
cal:RegionManager.RegionName="MainNavigationPanel"
DockPanel.Dock="Top"/>
</DockPanel>
</Border>
</DockPanel>
</Window>
在我的 MenuModule 中,我向该区域添加了一个视图,它显示得很好:
public void Initialize()
{
MainNavigationPresenter mainNavigationPresenter = this.container.Resolve<MainNavigationPresenter>();
IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
mainRegion.Add(new TestView());
}
问题是:我不想在我的 shell 中使用 ItemsControl,我想要一个 ContentControl,但是当我使用 ContentControl 时,它什么也不显示。
为什么 ItemsControl 显示我的视图而 ContentControl 不显示任何内容?
I've got an application based on Prism.
This is my shell:
<Window x:Class="AvarioCRM3.ShellV2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cal="http://www.codeplex.com/CompositeWPF" >
<DockPanel LastChildFill="True">
<Border
Padding="10"
DockPanel.Dock="Top"
Background="#ddd">
<DockPanel>
<ItemsControl
Name="MainNavigationPanel"
cal:RegionManager.RegionName="MainNavigationPanel"
DockPanel.Dock="Top"/>
</DockPanel>
</Border>
</DockPanel>
</Window>
In my MenuModule I add a view to the region and it shows fine:
public void Initialize()
{
MainNavigationPresenter mainNavigationPresenter = this.container.Resolve<MainNavigationPresenter>();
IRegion mainRegion = this.regionManager.Regions["MainNavigationPanel"];
mainRegion.Add(new TestView());
}
The problem is: I don't want an ItemsControl in my shell, I want a ContentControl, but when I use a ContentControl, it shows nothing.
Why would ItemsControl show my views and ContentControl show nothing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是因为 ContentControl 仅显示一个子项,而 ItemsControl 有多个子项吗?
我没有使用过 Prism,但 API 表明 IRegion 应该有多个子区域。 如果您使用的是 ContentControl,那么当我执行以下操作时会发生什么有点不明确:
Could this be because a ContentControl will only display a single child, whereas an ItemsControl has multiple children?
I have't worked with Prism, but the API suggests that an IRegion is expected to have multiple children. If you're using a ContentControl then it is a little ambiguous what happens when I do the following:
与具有 ContentControl 的 ItemsControl 不同,您还需要在添加视图后激活视图以使其可见。
Unlike the ItemsControl with a ContentControl you also need to activate the view once you have added it to make it visible.
我注意到您在初始化中执行此操作。 会不会太早了? 您是否尝试过使用注册而不是注入视图来查看是否改变了什么?
这不会解决您的问题,但它将证明问题是在您的区域实际可用之前尝试添加某些内容。 RegisterViewWithRegion 将延迟视图的创建和显示,直到该区域可用。
I noticed you are doing this in Initialize. Could be too early? Have you tried using registration rather than injection of your view to see if that changed anything?
This won't solve your problem, however it will prove that the problem is trying to add something before your region is actually available. RegisterViewWithRegion will delay the creation and display of the view until the region is available.