我的ContentControl中有一个奇怪的行为,并且不知道它为什么会这样。
这个Xaml代码列出了我的ObservableCollection的项目
<ItemsControl ItemsSource="{Binding Stops}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl>
<local:TripDetailListItemControl />
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
但这只显示列表的第一项
<ItemsControl ItemsSource="{Binding Stops}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl>
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Content">
<Setter.Value>
<local:TripDetailListItemControl/>
</Setter.Value>
</Setter>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
有什么不同?我错过了风格覆盖的Enumarator吗?
背景,为什么我需要它这样,是我在这个TripDetailListItemControl
中有一个属性改变了这个项目的视图。所以我希望这个样式中的DataTrigger以不同的方式显示它。
但该列表并未首先显示。我需要在Content Setter中添加什么才能显示所有项目?
添加基于:
<Style TargetType="{x:Type ContentControl}" BasedOn="{StaticResource {x:Type ContentControl}}">
要么:
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Content">
<Setter.Value>
<ContentPresenter></ContentPresenter>
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<local:TripDetailListItemControl/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>