-1

MyDashBoardSimpleCountObject有 2 个值:MyNameMyValue. 我使用一个ObservableCollection<DashboardSimpleCountObject>被调用的MyData.

我想展示一张图片,只要MyValuenull. 但是,图片(“ 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>

我究竟做错了什么?非常感谢您!:)

4

1 回答 1

0

看来,DynamicResource导致这个问题的性质。简单地改变DynamicResource就可以StaticResource了。

所以,DataTrigger从一开始就工作得很好。由于被加载为DynamicResource.

于 2017-08-17T13:55:57.163 回答