3

次のレイアウト ViewModels --DialogViewModel --GraphViewModel Views --DialogView --GraphView を持つ非常に単純な WPF テスト アプリケーションがあります。

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 のビューが見つかりません。」

私は何が欠けていますか?

4

1 に答える 1

3

私は以前にこれを掘り下げました。CM ソースで VS を開き、プロジェクト ソースで VS を開きました。CM ソースを持つ VS を使用して、プロジェクトを使用して他の VS に接続します。次に、プロジェクトを含む VS で、ビューを開きます。

私の記憶が正しければ、設計時に、SelectAssembliesビューとビュー モデルを含むアセンブリがコレクションに含まれていませんでした。

SelectAssembliesブートストラッパーでメソッドをオーバーライドしてしまったと思います。それExecute.IsInDesignModeが本当なら、それがメイン/唯一のアセンブリであっても、ビューとビューモデルを含むアセンブリを追加します。

于 2013-03-11T15:04:49.437 に答える