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
을 구현하고 두 개의 공용 속성 - ImageSource
및 BorderBrush
을 노출합니다.
생성자의 UserControl
에 대한 DataContext
을 SelectionContent
으로 설정합니다. 그러나 이것은 작동하지 않으며 WrapPanel
은 아무 것도 표시하지 않습니다.
출력 창을 확인해야합니다. 바인딩 오류가 표시됩니다. DataContext를 "SelectionContent"로 설정하면 ItemsSource를 다시 "SelectionContent"로 설정할 수 없습니다. DataContext를 "SelectionContent"로 설정하려면 (필자는 뷰 모델을 선호하지만 제 의견입니다) ItemsSource = "{Binding}"(현재 DataContext 인 "SelectionContent"에 바인딩 됨)을 사용하십시오. –
Brilliant! 그것은 SelectionContent에 대한 설정이 실제로 문제 였기 때문에'ItemsSource = "{Binding}"을 설정하고 문제를 해결했습니다. – Praetorian