0

I have a control template that is bound to a model property, lets say Property1. However, if Property2 is updated (regardless of value), i'd like to flash the background of the element that Property1 is bound to. I've seen many examples where a DataTrigger can be used for something similar, but in this case, i don't care what value the property changes to, just that it has changed.

thus far i have something like this:

<Style x:Key="QuotePriceCellStyle" TargetType="TextBlock">
...
...
    <DataTrigger Binding="{Binding Path=AskPrice, UpdateSourceTrigger=PropertyChanged}" >
        <DataTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation From="Red" To="Transparent" Duration="0:0:2" Storyboard.TargetProperty="Background.Color" RepeatBehavior="1x"/>
                </Storyboard>
            </BeginStoryboard>
        </DataTrigger.EnterActions>
    </DataTrigger>
</Style>

<ControlTemplate x:Key="QuotePrice" >
    <TextBlock Style="{StaticResource QuotePriceCellStyle}" Text="{Binding QuotePrice}">
</ControlTemplate>

The above obviously doesn't do what i needed. QuotePrice and AskPrice are properties on the model. ANy thoughts on how to get QuotePrice cell to highlight when AskPrice changes?

2 Answers 2

0

You can use a converter for your DataTrigger like this:

public class FlashConverter : IValueConverter
{
    private object oldvalue;
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null) return false;
        if (oldvalue == value) return false;
        else
        {
            oldvalue = value;
            return true;
        }

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

and your datatrigger will be:

<DataTrigger Binding="{Binding Path=AskPrice, Converter={StaticResource FlashConverter1}, UpdateSourceTrigger=PropertyChanged}" Value="True">

so in your converter you can decide when turn on the background.

0

I Opted to use a DataTrigger to conditionally bind the two cells to both and using an EventTrigger w/ NotifyTargetUpdated set true to trigger the actual flashing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.