저는 Silverlight에서 Prism 4를 사용하고 있고 ItemsControl을 사용하여 여러보기를 호스팅하려고합니다. 나는 모든 뷰가 지정된 ItemTemplate 안에 싸이게하거나 ItemStyle을 지정하여 Silverlight Toolkit의 Expander 컨트롤과 같은 것을 사용할 수있게하고 싶습니다. ItemTemplate을 지정하려고하면 처리되지 않은 System.NotSupportedException이 런타임에 throw됩니다.ItemsControl에 대한 TabControlRegionAdapter.ItemContainerStyle Attached Property와 비슷한 것이 있습니까?
ItemsControl.Items must not be a UIElement type when an ItemTemplate is set.
at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.GetContainerForItem(Object item, DependencyObject recycledContainer)
at System.Windows.Controls.ItemContainerGenerator.Generator.GenerateNext(Boolean stopAtRealized, Boolean& isNewlyRealized)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.GenerateNext(Boolean& isNewlyRealized)
at System.Windows.Controls.ItemsControl.AddContainers()
at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)
코드
<ItemsControl Regions:RegionManager.RegionName="DetailsRegion">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="1">
<ContentPresenter Content="{Binding}"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
당신은 어떻게 ItemsSource를 설정하는에게 도움이? 예외를 기반으로 명시 적으로 ItemsControl (itemControl.itemsControl.Items.Add())에 ItemsSource를 설정하는 대신 Binding을 통해 명시 적으로 항목을 추가하는 것처럼 들리거나 Codebehind (itemscontrol.ItemsSource = myCollection). –
Xaml에서 ItemsSource를 설정하지 않습니다. Prism4에서 기본 ItemsControlRegionAdapter를 사용하고 있습니다. ItemsSource를 void Adapt (IRegion region, ItemsControl regionTarget)에 this : regionTarget.ItemsSource = region.Views로 설정합니다. 뷰는 IViewsCollection : IEnumerable
컬렉션에 무엇이 있는지 알고 있니? SL은 이미 DataTemplate의 DataContext로 사용하는 대신 렌더링하려고 시도 할 수있는 요소라는 것을 SL이 알고 있기 때문에 문제가 될 것이라고 생각합니다. –