我有一个带有ContentControl的窗口,我用它来模拟向导导航,它运行得很好。为了重构某些代码,我在向导的一个UserControl中提取了一个窗体,而我在另一个窗口中使用的方式完全相同.
我提取的UserControl在另一个窗口(不是向导窗口)上工作得很好,但在向导中的UserControl中没有工作.我在这两种情况下都使用ContentControl ..。
我没有任何错误..。我已经调试过了,在这两种情况下都调用了构造函数,但是在向导中它不会出现,只是这样。
简单窗口中的代码是:
<Controls:MetroWindow x:Class="Desktop.Views.FilePropertiesViewModel">
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Visible">
<ContentControl x:Name="DocumentPropertyListViewModel" />
</ScrollViewer>
</Grid>
</Controls:MetroWindow>在后面的代码中,在我的窗口的构造函数中
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引用,我想不出如何用另一种方法.
我在这里做错事了?
发布于 2014-11-05 21:14:29
你可以试试这个..。
<ContentControl x:Name="Wizard"> <ContentControl cm:View.Model="{Binding DocPropListViewProp}" /> </ContentControl>
其中,DocPropListViewProp是主窗口中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); }仍然对上面的声明感到困扰,您提供的代码片段表示您在代码背后拥有它,您的意思是ViewModel吗?
另外,您为IoC使用的容器是什么: MEF、SimpleContainer等.?没什么?
https://stackoverflow.com/questions/26742021
复制相似问题