Memory leak in datagrid with style animations

Mar 23, 2009 at 6:27 AM
Edited Mar 23, 2009 at 6:28 AM
Hi, I'm using the datagrid to flash cells on and off, and have noticed that my application has a memory leak. The offending class is Windows.Media.Animation.AnimationClock. When profiling my application the instance count for this class is ever increasing. I'm new to WPF, so it's possible I'm doing something incorrectly in the xaml. Does anyone have a workaround for this issue?

    <Window.Resources>
        <Style TargetType="{x:Type MsWpfTest1:NumericTextBlock}" x:Key="blinkingCellGridStyle">
            <Style.Resources>
                <MsWpfTest1:NumericTextConverter x:Key="_numericTextConverter" />
                <Storyboard x:Key="AniToRed">
                    <ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="0:0:0" From="White" To="Red"/>
                    <ColorAnimation Storyboard.TargetProperty="Background.Color" BeginTime="0:0:1"  Duration="0:0:0" From="Red" To="White"/>
                </Storyboard>
            </Style.Resources>
            <Style.Triggers>
                <DataTrigger Value="+1">
                    <DataTrigger.Binding>
                        <MultiBinding Converter="{StaticResource _numericTextConverter}">
                            <Binding RelativeSource="{RelativeSource Self}" Path="Text"/>
                            <Binding RelativeSource="{RelativeSource Self}" Path="OldValue"/>
                        </MultiBinding>
                    </DataTrigger.Binding>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource AniToRed}" />
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Value="-1">
                    <DataTrigger.Binding>
                        <MultiBinding Converter="{StaticResource _numericTextConverter}">
                            <Binding RelativeSource="{RelativeSource Self}" Path="Text"/>
                            <Binding RelativeSource="{RelativeSource Self}" Path="OldValue"/>
                        </MultiBinding>
                    </DataTrigger.Binding>
                    <DataTrigger.EnterActions>
                        <BeginStoryboard Storyboard="{StaticResource AniToRed}" />
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>

    <my:DataGrid Height="2450" Name="dataGrid1" Width="1600" AutoGenerateColumns="false" ItemsSource="{Binding mDataRowList}">
        <my:DataGrid.Columns>
            <my:DataGridTemplateColumn>
                <my:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <MsWpfTest1:NumericTextBlock Width="90" NumericText="{Binding DataSourceFieldName1}" Background="White" Foreground="Black" Style="{StaticResource blinkingCellGridStyle}"/>
                    </DataTemplate>
                </my:DataGridTemplateColumn.CellTemplate>
            </my:DataGridTemplateColumn>
            <my:DataGridTemplateColumn>
                <my:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <MsWpfTest1:NumericTextBlock Width="90" NumericText="{Binding DataSourceFieldName2}" Background="White" Foreground="Black" Style="{StaticResource blinkingCellGridStyle}"/>
                    </DataTemplate>
                </my:DataGridTemplateColumn.CellTemplate>
            </my:DataGridTemplateColumn>
        </my:DataGrid.Columns>
    </my:DataGrid>