我已經創建了我已經應用到我列一個像這樣的DataGridCell模板:排序的DataGrid而動畫細胞引起的異常
<DataGridTextColumn Binding="{Binding LastUpdated}"
IsReadOnly="True" CanUserReorder="False"
CanUserSort="False" CanUserResize="False"
CellStyle="{StaticResource DataGridCellStyle1}"
/>
而且模板看起來是這樣的:
<ControlTemplate TargetType="{x:Type DataGridCell}">
<ControlTemplate.Resources>
<Storyboard x:Key="CellChangedStoryboard">
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="DGC_Border">
<EasingColorKeyFrame KeyTime="0" Value="LightGreen"/>
<EasingColorKeyFrame KeyTime="0:0:8" Value="Red"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Border x:Name="DGC_Border" Background="Red">
<ContentPresenter />
<i:Interaction.Triggers>
<ei:TimerTrigger MillisecondsPerTick="1000" >
<ei:ControlStoryboardAction Storyboard="{StaticResource CellChangedStoryboard}"/>
</ei:TimerTrigger>
</i:Interaction.Triggers>
</Border>
</ControlTemplate>
在這個例子我使用Blend TimerTrigger來觸發動畫,但它並不重要,我觸發了我的動畫,當我嘗試對DataGrid進行排序時,它總是崩潰(通過單擊列標題之一)
如果我刪除故事板,那麼它不會在排序時崩潰。
例外情況是InvalidOperationException:在'System.Windows.Controls.Border'的名稱範圍中找不到'DGC_Border'名稱。
我懷疑,當DataGrid排序時,它會破壞或以其他方式破壞單元格/列和正在運行的動畫不能再找到它正在動畫的單元格。
爲什麼會發生異常,我該如何阻止它? 謝謝
更新:似乎工作好吧,如果我用<ControlTemplate.Triggers>
來觸發StoryBoard。不幸的是,這並不是解決方案,因爲我需要在綁定屬性更改時播放故事板。
你是否試圖從本質上重新創建驗證用戶界面,但動畫? – 2010-12-01 04:21:20