2014-10-28 4 views
0

XAML을 사용하여 매우 간단한 작업을하고 싶습니다.Items ViewControls with ViewModels

'UserControl B'에서 호스팅되는 ItemControl에서 'userControl A'(viewModels 'ViewModel A'포함)의 목록을 표시하려고합니다.

'ViewModel B'는 'UserControls A'의 observableCollection 인 속성을 포함합니다. '된 UserControls A'의 ctor에에서

는 내가 설정 한 다음 'userControlB'의 ctor에의
Me.DataContext = New ViewModelA() 

, 나는 동일하게 설정하지만, '뷰 모델 B'로했습니다.

'ViewModel A'에는 'Row'와 'Col'의 두 가지 속성 (정수)이 있습니다.

내가 원하는 'UserControl A'및 'Col'및 'Row'의 값을 'UserControl B'에서 호스팅되는 Grid에서 바인딩 할 수 있습니다. 여기

내가 무슨 짓을했는지 있습니다 : 에서 UserControl B :

<ItemsControl ItemsSource="{Binding ListOfUserControl_A}" Margin="1.5"> 
      <ItemsPanelTemplate> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
         <ColumnDefinition /> 
        </Grid.ColumnDefinitions> 
       </Grid> 
      </ItemsPanelTemplate> 
      <ItemsControl.ItemContainerStyle> 
       <Style> 
        <Setter Property="Grid.Column" Value="{Binding Col}" /> 
        <Setter Property="Grid.Row" Value="{Binding Row}" /> 
       </Style> 
      </ItemsControl.ItemContainerStyle> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <local:UserControl_A/> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 

컬렉션이 제대로이 과정 전에 가득합니다.

런타임에는 프랑스어로 번역 된이 오류가 있습니다. " 'ItemsSource'를 사용하려면 컬렉션이 비어 있어야합니다." 내가 잘못 뭐하는 거지

내가 전에 '는 ItemTemplate을하고 ItemTemplateSelector이 UserControl_B에 유효하지 않은'것이 었었던 다른 오류 ...

?

답변

0

ItemsPanelTemplateItemsControl.ItemsPanel 태그에 넣는 것을 잊어 버렸습니다. 항목으로 이후 그 ItemsControl 취급 ItemsPanelTemplate없이 당신은 이미 당신이 그 오류

<ItemsControl ItemsSource="{Binding ListOfUserControl_A}" Margin="1.5"> 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 
+0

세상에, 이런 바보를 얻을 수 ItemsSource을 설정합니다. Thx 남자. – Thib