1
我想爲我的ItemsControl使用單選模式。所以我改變了我的ItemsControl到一個ListBox,但是我收到一個異常「用於'ContentPresenter'類型的樣式不能用於輸入'ListBoxItem'。」這是怎麼回事?我不能使用ContentPresenter的ListBoxes?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>
如果你的問題與Visual Studio本身無關,那就不要使用標籤。 –