ContentControl - ItemsControl 中的内容 setter
ContentControl - Content setter inside ItemsControl
我的 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
中有一个 Proeprty 可以改变这个项目的视图。所以我想要这种样式的 DataTrigger 以不同的方式显示它。
但是列表一开始并没有显示。我需要在内容 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>
我的 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
中有一个 Proeprty 可以改变这个项目的视图。所以我想要这种样式的 DataTrigger 以不同的方式显示它。
但是列表一开始并没有显示。我需要在内容 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>