MyDashBoardSimpleCountObject
有 2 个值:MyName
和MyValue
. 我使用一个ObservableCollection<DashboardSimpleCountObject>
被调用的MyData
.
我想展示一张图片,只要MyValue
是null
. 但是,图片(“ loading
”)只显示在我的最后一项ObservableCollection
(不管那里有多少项)。一旦MyValue
设置 a (除 之外的任何内容null
),它就会自动更新并正确显示 - 在所有项目上都可以正常工作。
<ItemsControl x:Name="_control" ItemsSource="{Binding MyData}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="25">
<Label FontSize="14" Content="{Binding MyName}" />
<Label Margin="0,25" HorizontalContentAlignment="Right" FontSize="29" FontWeight="ExtraBold" Foreground="{Binding MyColor}">
<Label.Style>
<Style TargetType="{x:Type Label}">
<Setter Property="Content" Value="{Binding MyValue}" />
<Style.Triggers>
<DataTrigger Binding="{Binding MyValue}" Value="{x:Null}">
<Setter Property="Content">
<Setter.Value>
<Image Width="32" Height="32" Source="{DynamicResource loading}" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我究竟做错了什么?非常感谢您!:)