简体   繁体   English

另一个ContentControl中的WPF ContentControl不显示

[英]WPF ContentControl inside another ContentControl not showing

I have a Window with a ContentControl that I use to simulate a Wizard navigation that's working just fine. 我有一个带有ContentControl的窗口,该窗口用于模拟向导导航,该向导运行正常。 In order to refactor some code I have extract a form inside of one of the UserControl of the Wizard that I'am using in another Window in the exactly same way... 为了重构一些代码,我以完全相同的方式在另一个Window中使用的向导的UserControl中提取了一个表单...

The UserControl that I've extract is working fine on the other window (Not the wizard one), but not inside of my UserControl inside of the Wizard... I'm using ContentControl in both situations... 我提取的UserControl在其他窗口(不是向导)上运行良好,但不在向导的UserControl内部...在两种情况下都使用ContentControl。

I don't get any error... I've debugged and the constructor is been called in both cases, but inside of the Wizard it doens't appear, just that. 我没有收到任何错误...经过调试,在两种情况下都调用了构造函数,但是在向导内部却没有出现,仅此而已。

The code from the simple Window is: 来自简单Window的代码是:

<Controls:MetroWindow x:Class="Desktop.Views.FilePropertiesViewModel">
  <Grid>
     <ScrollViewer VerticalScrollBarVisibility="Visible">
        <ContentControl x:Name="DocumentPropertyListViewModel" />
     </ScrollViewer>
  </Grid>
</Controls:MetroWindow>

And in the code behind, in the constructor of my Window 在后面的代码中,在我的Window的构造函数中

public DocumentPropertyListViewModel DocumentPropertyListViewModel { get; set; }
public FilePropertiesViewModel(){
   this.DocumentPropertyListViewModel = new DocumentPropertyListViewModel(File.Properties, false);
}

The difference, as as said is (as a reference, not a real code): 如前所述,区别是(作为参考,而不是实际代码):

<ContentControl x:Name="Wizard"> <!-- Loading plenty of UserControls>
    <ContentControl x:Name="DocumentPropertyListViewModel" />  <!-- One of the UserControls has this -->
</ContentControl>

By the way, I'm using Caliburn.Micro, that's why I'm using ContentControl instead of a normal UserControl reference, I couldn't figured it out how to do the other way... 顺便说一句,我正在使用Caliburn.Micro,这就是为什么我使用ContentControl而不是普通的UserControl引用的原因,我不知道该怎么做...

I'am doing something wrong here? 我在这里做错什么了?

you might give this a try... 您可以尝试一下...

<ContentControl x:Name="Wizard"> <ContentControl cm:View.Model="{Binding DocPropListViewProp}" /> </ContentControl>

Where DocPropListViewProp is a viewmodel property of type DocumentPropertyListViewModel in your main window viewmodel 其中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); } Still troubled by the statement above with the code fragment that you provided saying you had it in the codebehind, did you mean 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吗?

Also what container are you using for IoC: MEF, SimpleContainer, etc...? 您还为IoC使用哪个容器:MEF,SimpleContainer等...? Nothing? 没有?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM