2011-01-04 5 views
1

ObservableCollection에 바인딩하여 Silverlight 툴킷의 WrapPanel을 채울 방법이 있습니까? 프로그래밍 방식으로 WrapPanel을 채우거나 XAML의 각 항목을 명시 적으로 추가하여 툴킷 예제 자체를 포함하여 지금까지 본 모든 예제를 채 웁니다.WP7 WrapPanel 및 MVVM

도움 주셔서 감사합니다.

편집 : Geert van Horrik's advice 다음은 내가 바인딩을 통해 WrapPanel를로드 할 ItemsControl를 사용했습니다.

<ScrollViewer VerticalScrollBarVisibility="Auto" 
       Height="440" 
       Margin="0,12,0,0"> 

    <ItemsControl ItemsSource="{Binding SelectionContent}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 

     <Border BorderThickness="1" 
       CornerRadius="4" 
       BorderBrush="{Binding BorderBrush}"> 

      <toolkit:GestureService.GestureListener> 
      <toolkit:GestureListener Tap="OnWrapPanelTapped" 
            DoubleTap="OnWrapPanelDoubleTapped" /> 
      </toolkit:GestureService.GestureListener> 

      <Image Source="{Binding ImageSource}" 
       MaxHeight="48" 
       MaxWidth="48" 
       Margin="16" /> 
     </Border> 

     </DataTemplate> 
    </ItemsControl.ItemTemplate> 

    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
     <toolkit:WrapPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
    </ItemsControl> 
</ScrollViewer> 

SelectionContent 뒤에이 UserControl의 코드에 ObservableCollection 존재 :이 XAML입니다. SelectionItem 개체로 구성되며 INotifyPropertyChanged을 구현하고 두 개의 공용 속성 - ImageSourceBorderBrush을 노출합니다.

생성자의 UserControl에 대한 DataContextSelectionContent으로 설정합니다. 그러나 이것은 작동하지 않으며 WrapPanel은 아무 것도 표시하지 않습니다.

+0

출력 창을 확인해야합니다. 바인딩 오류가 표시됩니다. DataContext를 "SelectionContent"로 설정하면 ItemsSource를 다시 "SelectionContent"로 설정할 수 없습니다. DataContext를 "SelectionContent"로 설정하려면 (필자는 뷰 모델을 선호하지만 제 의견입니다) ItemsSource = "{Binding}"(현재 DataContext 인 "SelectionContent"에 바인딩 됨)을 사용하십시오. –

+0

Brilliant! 그것은 SelectionContent에 대한 설정이 실제로 문제 였기 때문에'ItemsSource = "{Binding}"을 설정하고 문제를 해결했습니다. – Praetorian

답변

3

ItemsControl을 사용해야합니다. 그런 다음 WrapPanel을 항목 패널로 설정할 수 있습니다.

<ItemsControl ItemsSource="{Binding MyItemsSource}"> 
    <ItemsControl.ItemsPanel> 
    <WrapPanel /> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 
+0

안녕하세요, 답장을 보내 주셔서 감사합니다. 나는 당신의 충고를 따랐지만 그것이 효과를 발휘하지 못하는 것 같습니다. 제 편집 된 질문을보십시오. 다시 한 번 감사드립니다! – Praetorian

+0

WrapPanel이 ItemsPanelTemplate에 포함되어 있어야한다고 생각합니다. –