-1

My DashBoardSimpleCountObject has 2 values: MyName and MyValue. I use an ObservableCollection<DashboardSimpleCountObject> called MyData.

I want to show a picture, as long as MyValue is null. However, the picture ("loading") is only shown at the last item of my ObservableCollection (no matter, how many items are in there). As soon as a MyValue is set (with anything other than null), it is automatically updated and shown correctly - that works fine at all items.

<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>

What am I doing wrong? Thank you very much in advance! :)

Grent
  • 21
  • 6
  • Just found out, it has something to do with the `DynamicResource`. If I don't set the `Content` to an image in the `DataTrigger`, but to some default text, it works like it should. It seems, the picture will load in one single item only. – Grent Aug 17 '17 at 13:49
  • I took quite some time to google and find a solution, but obviously didn't know, what to look for - as I didn't suspect the problem to lie with `DynamicResource`. So, sorry for the "bad" question - I try to do better next time. (Still, posting a question on here is always my **last** straw.) – Grent Aug 18 '17 at 08:13

1 Answers1

0

It seems, the nature of DynamicResource causes this issue. Simply changing DynamicResource to StaticResource did the trick.

So, the DataTrigger worked just fine from the beginning. The image simply did only show up once due to being loaded as a DynamicResource.

Grent
  • 21
  • 6