私はSilverlightでPrism 4を使用していますが、ItemsControlを使用して複数のビューをホストしたいと考えています。すべてのビューを指定されたItemTemplateの中にラップするか、ItemStyleを指定できるようにして、Silverlight ToolkitのExpanderコントロールのようなものを使用できるようにします。 ItemTemplateを指定しようとすると、未処理のSystem.NotSupportedExceptionが実行時にスローされます。ItemsControlのTabControlRegionAdapter.ItemContainerStyle Attachedプロパティに似た何かがありますか?
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を設定するのに役立ちますか?例外に基づいて、ItemsSourceを通常Binding経由で設定するのではなく、ItemsControl.itemsControl.Items.Add()で明示的にアイテムをコントロールに追加しているかのように聞こえるか、Codebehind(itemscontrol.ItemsSource =私のコレクション)。 –
XamlにItemsSourceを設定していません。私はPrism4でデフォルトのItemsControlRegionAdapterを使用しています。 ItemsSourceをvoid Adapt(IRegion region、ItemsControl regionTarget)にthis:regionTarget.ItemsSource = region.Viewsに設定します。ビューはIViewsCollection:IEnumerable
あなたはコレクションに何があるか知っていますか?私は、SLがDataTemplateのDataContextとして使用する代わりに、レンダリングしようとしている要素であることをSLが知っているので、それが問題になるかもしれないと思います。 –