Jasti
Jasti

Reputation: 947

Stop ProgressBar animation after Value = Maximum

I have added an animation for progress bar.

I am trying to stop the animation after maximum fill (changes every time). I am generating the progress bar maximum value from code behind based on the number of files I need to process.

Following is the code snippet I have

<Trigger Property="Value" Value="10">
    <Setter Property="Visibility" TargetName="Animation" Value="Collapsed"/>

</Trigger>

Above trigger works when the maximum value for progressbar is 10, but my question is how to update this value to dynamically generated maximum value.

Could some one please help me out?

I really appreciate your time

Upvotes: 3

Views: 1889

Answers (2)

Abe Heidebrecht
Abe Heidebrecht

Reputation: 30498

A more complicated way of doing this (but also more reusable) would be to use a DataTrigger with a MultiBinding and a IMultiValueConverter:

public class EqualsConverver : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, 
        object parameter, CultureInfo culture)
    {
        if (values.Length < 1)
            return Binding.DoNothing;

        var obj = values[0];
        for (int i = 1; i < values.Length; ++i)
        {
            if (!obj.Equals(values[i]))
                return false;
        }

        return true;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, 
        object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

And then your trigger would look like:

<DataTrigger Value="True">
    <DataTrigger.Binding>
        <MultiBinding Converter="{StaticResource equalsConverter}">
            <Binding Path="Value" RelativeSource="{RelativeSource Self}" />
            <Binding Path="Maximum" RelativeSource="{RelativeSource Self}" />
        </MultiBinding>
    </DataTrigger.Binding>
    <Setter Property="Visibility" TargetName="Animation" Value="Collapsed"/>
</DataTrigger>

Upvotes: 3

Lee Louviere
Lee Louviere

Reputation: 5262

Instead of the Trigger, and since you already have code behind, you can register for the animation's completed event.

Upvotes: 1

Related Questions