Caliburn mirco在设计时没有找到视图

时间:2013-03-11 13:06:52

标签: wpf caliburn.micro

我有一个非常简单的WPF测试应用程序,具有以下布局 的ViewModels --DialogViewModel --GraphViewModel 查看 --DialogView --GraphView

DialogViewModel有以下代码:

public class DialogViewModel : Screen {
    #region Graph
    private GraphViewModel m_gvmGraph;
    public GraphViewModel Graph {
        get {
            if(m_gvmGraph == null) {
                m_gvmGraph = new GraphViewModel();
            }
            return m_gvmGraph;
        }
        set {
            if(m_gvmGraph != value) {
                m_gvmGraph = value;
                NotifyOfPropertyChange("Graph");
            }
        }
    }
    #endregion

    public DialogViewModel() {
        DisplayName = "Graph Dialog";
    }

GraphViewModel没有代码。

DialogView(UserControl)如下所示:

d:DataContext="{d:DesignInstance Type=VMs:DialogViewModel, IsDesignTimeCreatable=True}"
Cal:Bind.AtDesignTime="True"
Width="1000" Height="600">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="200"/>
    </Grid.ColumnDefinitions>
    <ContentControl x:Name="Graph"  />
</Grid>

GraphView(UserControl)如下所示:

    d:DataContext="{d:DesignInstance Type=VMs:GraphViewModel, IsDesignTimeCreatable=True}"
Cal:Bind.AtDesignTime="True"
d:DesignHeight="600" d:DesignWidth="800">
<Grid>
    <Grid>
        <Grid>
            <TextBlock Text="Test" />
        </Grid>
    </Grid>
</Grid>

(我以后需要嵌套的网格 - 这里没关系。)

这在运行时可视为预期(查看加载等)。 所以我猜(大多数)做得对。

但是在设计时(当我打开GraphView.xaml时,我得到“无法找到XXXX.ViewModels.GraphViewModel的视图。”

我错过了什么?

1 个答案:

答案 0 :(得分:3)

我之前已经挖过这个。我有一个VS打开CM源和VS打开项目源。对于具有CM源的VS,我将附加到项目的另一个VS.然后在带项目的VS中,打开视图。

如果我没记错的话,在设计时,SelectAssemblies集合并不包含包含视图和视图模型的程序集。

我相信我最终覆盖了引导程序中的SelectAssemblies方法,如果Execute.IsInDesignMode为真,则添加包含视图和视图模型的程序集,即使它是主要/唯一程序集。 / p>