我正在开发windows应用程序。在该应用程序中,我使用了MyToolkit数据网格。我想通过使特定的单元格数据在特定的情况下闪烁来突出显示数据网格的行。
发布于 2016-07-27 16:48:28
您可以在项目中安装Microsoft.Xaml.Behaviors.Uwp.Managed。然后使用DataTriggerBehavior使特定单元格数据在特定情况下闪烁。
首先,您需要像这样使用这个包:
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Media="using:Microsoft.Xaml.Interactions.Media"例如,您可以这样设计DataGrid的单元格:
<controls:DataGridTemplatedColumn Width="0.7*" CanSort="False" Header="LastName">
<controls:DataGridTemplatedColumn.CellTemplate>
<DataTemplate>
<Grid Height="30">
<Grid.Resources>
<Storyboard x:Key="std" x:Name="std">
<ColorAnimation From="Red" To="Blue" Duration="0:0:3" RepeatBehavior="Forever" AutoReverse="True"
Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
Storyboard.TargetName="lastnamePanel" />
</Storyboard>
</Grid.Resources>
<StackPanel Name="lastnamePanel" Background="AliceBlue">
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Binding="{Binding Lastname}" ComparisonCondition="Equal" Value="Mike">
<Media:ControlStoryboardAction Storyboard="{StaticResource std}" />
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
<TextBlock x:Name="lastnameTxt" Text="{Binding Lastname}" TextAlignment="Center" VerticalAlignment="Center" Margin="0,5,0,0"></TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</controls:DataGridTemplatedColumn.CellTemplate>
</controls:DataGridTemplatedColumn>当lastnameTxt的Text不等于"Mike“时,则播放Storyboard。这是渲染图像:

您需要注意的一点是,应该在lastnamePanel中设置初始Background,否则将不会播放故事板。
https://stackoverflow.com/questions/38592634
复制相似问题