XamlAnimatedGif / WpfAnimatedGif

A simple library to display animated GIF images in WPF, usable in XAML or in code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binding RepeatBehavior

neuraltoys opened this issue · comments

Hi,
I am trying to bind the RepeatBehavior parameter to a view model property like this:

    <Image Stretch="None" gif:ImageBehavior.RepeatBehavior="Forever">
        <Image.Style>
            <Style TargetType="Image">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=HasInvalid, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="False">
                        <Setter Property="gif:ImageBehavior.AnimatedSource" Value="pack://application:,,,/Resources/a.png" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=HasInvalid, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="True">
                        <Setter Property="gif:ImageBehavior.AnimatedSource" Value="pack://application:,,,/Resources/b.gif" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=AnimateInvalid, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="False">
                        <Setter Property="gif:ImageBehavior.RepeatBehavior" Value="1x" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=AnimateInvalid, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="True">
                        <Setter Property="gif:ImageBehavior.RepeatBehavior" Value="Forever" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Image.Style>
    </Image>

I see the property changing but the animation doesn't stop.
What am I missing?

Not sure why this doesn't work... does the problem also affect the AnimatedSource property, or just RepeatBehavior? (i.e. does the image change when the HasInvalid property changes?)

(btw, you don't need UpdateSourceTrigger for a OneWay binding)

yes, the image change works fine.
is it possible that the gif has something inside that overwrites the repeat?

is it possible that the gif has something inside that overwrites the repeat?

I don't think so... A change to either AnimatedSource or RepeatBehavior should cause the animation to restart with the new settings.

But what are you trying to do exactly anyway? You say that the animation doesn't stop; is it what you're trying to do? You could try setting AutoStart to false instead of changing the RepeatBehavior

ah, that was stupid
I had on the image: gif:ImageBehavior.RepeatBehavior="Forever"
because I thought this would be a default value that I can override with the binding
now I have removed it and it works
sorry for wasting your time

Ah, indeed! I think it would have worked in a DataTemplate trigger, but not in a Style trigger