[英]WPF ContentControl inside another ContentControl not showing
我有一个带有ContentControl的窗口,该窗口用于模拟向导导航,该向导运行正常。 为了重构一些代码,我以完全相同的方式在另一个Window中使用的向导的UserControl中提取了一个表单...
我提取的UserControl在其他窗口(不是向导)上运行良好,但不在向导的UserControl内部...在两种情况下都使用ContentControl。
我没有收到任何错误...经过调试,在两种情况下都调用了构造函数,但是在向导内部却没有出现,仅此而已。
来自简单Window的代码是:
<Controls:MetroWindow x:Class="Desktop.Views.FilePropertiesViewModel">
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Visible">
<ContentControl x:Name="DocumentPropertyListViewModel" />
</ScrollViewer>
</Grid>
</Controls:MetroWindow>
在后面的代码中,在我的Window的构造函数中
public DocumentPropertyListViewModel DocumentPropertyListViewModel { get; set; }
public FilePropertiesViewModel(){
this.DocumentPropertyListViewModel = new DocumentPropertyListViewModel(File.Properties, false);
}
如前所述,区别是(作为参考,而不是实际代码):
<ContentControl x:Name="Wizard"> <!-- Loading plenty of UserControls>
<ContentControl x:Name="DocumentPropertyListViewModel" /> <!-- One of the UserControls has this -->
</ContentControl>
顺便说一句,我正在使用Caliburn.Micro,这就是为什么我使用ContentControl而不是普通的UserControl引用的原因,我不知道该怎么做...
我在这里做错什么了?
您可以尝试一下...
<ContentControl x:Name="Wizard"> <ContentControl cm:View.Model="{Binding DocPropListViewProp}" /> </ContentControl>
其中DocPropListViewProp
是主窗口viewmodel中类型为DocumentPropertyListViewModel的viewmodel属性
And in the code behind, in the constructor of my Window public DocumentPropertyListViewModel DocumentPropertyListViewModel { get; set; } public FilePropertiesViewModel(){ this.DocumentPropertyListViewModel = new DocumentPropertyListViewModel(File.Properties, false); }
And in the code behind, in the constructor of my Window public DocumentPropertyListViewModel DocumentPropertyListViewModel { get; set; } public FilePropertiesViewModel(){ this.DocumentPropertyListViewModel = new DocumentPropertyListViewModel(File.Properties, false); }
上面的语句仍然让您感到困惑,您提供的代码片段说您在代码的后面有该片段,您是说ViewModel吗?
您还为IoC使用哪个容器:MEF,SimpleContainer等...? 没有?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.