【发布时间】:2020-09-02 18:17:03
【问题描述】:
下午好,
我将双精度列表 (Latlng) 绑定到 ItemsControl 和 TextBlock 我想在绑定的列表计数为 0 时创建自定义文本。使用代码我有当ItemsControl 的ItemsSource 是该列表时,TextBlock 为空。
我做错了什么?
顺便说一句,Latlng 列表是一个类的属性。
<ItemsControl Name="icLatLng" ItemsSource="{Binding Latlng}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock FontFamily="Arial" FontSize="14">
<TextBlock.Style>
<Style>
<Setter Property="TextBlock.Text" Value="{Binding}"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=Items.Count}" Value="0">
<Setter Property="TextBlock.Text" Value="—"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
提前致谢。
【问题讨论】: