【发布时间】:2023-03-25 22:55:02
【问题描述】:
我正在开发 Windows 应用程序。在该应用程序中,我使用的是 MyToolkit 数据网格。我想通过在特定情况下使特定单元格数据闪烁来突出显示数据网格的行。
【问题讨论】:
-
这不能同时是 WPF 和 UWP。请显示代码,不清楚你在问什么
标签: xaml data-binding uwp
我正在开发 Windows 应用程序。在该应用程序中,我使用的是 MyToolkit 数据网格。我想通过在特定情况下使特定单元格数据闪烁来突出显示数据网格的行。
【问题讨论】:
标签: xaml data-binding uwp
您可以在您的项目中安装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。这是渲染图像:
需要注意的一点是初始Background 应该设置为lastnamePanel,否则故事板将无法播放。
【讨论】: