2013-10-15 3 views
0

InternalViewModel 유형의 속성이있는 ViewModel을 가지며 컬렉션 속성을 갖습니다. DesignInstance : 중첩 된 컬렉션 속성이 인식되지 않습니다.

다음 구문을 필요로 내부 수집을 결합, 뷰의 DataContext에이 뷰 모델의 인스턴스 인 것을 감안할 때 예상대로 런타임시

{Binding InternalViewModelProperty.Collection} 

그냥 작동합니다. 그러나 DesignInstance를 프록시로 사용하여 내 ViewModel 객체를 나타내는 경우 디자인 타임에 콜렉션이 전혀 표시되지 않습니다 (예 : 자동 생성 열 없음).

{Binding Collection} 

는 그 다음 디자인 타임에 다시 작동합니다

내가 속임수와 뷰 모델 속성으로 컬렉션 속성을 노출하고 바인딩을 변경하면

.

ViewModel에 속한 다른 속성 내의 속성으로 중첩 된 컬렉션이 디자인 타임에 다르게 작동하는 이유가 있습니까? 이것이 DesignInstance의 한계입니까? 여기

가 XAML 코드입니다 : 그 '아무튼 경우

d:DataContext="{d:DesignInstance Type=local:MyViewModel, IsDesignTimeCreatable=True}" 

: 모든

<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> 
+0

InternalViewModelProperty는 인터페이스 INotifyPropertyChanged를 노출합니까? – Tony

+0

예. 그러나 Collection 속성은 읽기 전용이므로 변경된 속성으로 "Collection"을 사용하여 PropertyChanged를 발생시키지 않습니다. AFAIK이게 문제가 아니지, 그렇지? – Crono

+0

표시 xaml DesignInstance를 어떻게 설정 했습니까? –

답변

1

첫째, 문제는이 같은, 당신의 d:DesignInstance 선언에 IsDesignTimeCreatable=True를 추가 할 필요가 간단하게 할 수있다 뷰 모델에 매개 변수없는 생성자가 없거나 생성자에 InternalViewModelProperty 값을 설정하지 못하는 것일 수 있습니다.

즉, 뷰 모델에는 매개 변수가없는 생성자가 있어야하며 해당 생성자 내에서 InternalViewModelProperty을 null이 아닌 값으로 설정해야합니다. 또한속성이 InternalViewModelProperty인지 확인해야합니다. 또한 null이 아닌 값으로 설정해야합니다.

+0

그게 다야! 정말 고맙습니다! :디 – Crono

관련 문제