2011-07-28 17 views
1

ItemsControlにSingle Selectionモードを使用しようとしています。だから私はItemsControlをListBoxに変更しましたが、例外が発生しました。 "'ContentPresenter'型のスタイルは 'ListBoxItem'の型には適用できません。ここに何がありますか? ListBoxにContentPresenterを使用できないのですか?ListBox付きContentPresenter

<ListBox SelectionMode="Single" ItemsSource="{Binding}" MinHeight="200" MinWidth="200"> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <UniformGrid></UniformGrid> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 

    <ListBox.ItemContainerStyle> 
     <Style TargetType="ContentPresenter"> 
      <Setter Property="Grid.Row" Value="{Binding X}" /> 
      <Setter Property="Grid.Column" Value="{Binding Y}" /> 
     </Style> 
    </ListBox.ItemContainerStyle> 

    <ListBox.ItemTemplate> 
     <DataTemplate DataType="ObservableCollection"> 
      <Border BorderBrush="Black" BorderThickness="0.5" Background="Beige"> 
       <clr:Cell Content="{Binding Character}"></clr:Cell> 
      </Border> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

質問がVisual Studio自体と関係がない場合は、タグを使用しないでください。 –

答えて

5

スタイルは、常に作成されるものなので、ListBoxItemをターゲットにする必要があります。 ListBoxのテンプレートとデータテンプレートのドキュメントと例は、hereです。

+0

最初の文は質問に答えますが、2行目は問題を泥沼にしています(多分例が変わったのでしょうか?)。実際の例を使って2番目の文を削除します。