私は、InternalViewModel タイプのプロパティを持つ ViewModel を持っています。これには Collection プロパティがあります。
ビューの DataContext が ViewModel のインスタンスである場合、内部コレクションをバインドするには次の構文が必要になります。
{Binding InternalViewModelProperty.Collection}
実行時には、期待どおりに機能します。ただし、ViewModel オブジェクトを表すプロキシとして DesignInstance を使用すると、設計時にコレクションがまったく表示されません (たとえば、列が自動生成されません)。
Collection プロパティを ViewModel プロパティとしてチートして公開し、バインディングを次のように変更した場合:
{Binding Collection}
その後、設計時に再び機能します。
ViewModel に属する別のプロパティ内のプロパティとしてネストされたコレクションが設計時に異なる動作をする理由はありますか? これは DesignInstance の制限ですか?
XAML コードは次のとおりです。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:LocalNS"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
mc:Ignorable="d"
x:Class="MyUserControl"
d:DataContext="{d:DesignInstance Type=local:MyViewModel}"
>
<Grid>
<DataGrid ItemsSource="{Binding InternalViewModelProperty.Collection}"/>
</Grid>
</UserControl>