【问题标题】:Customize specific row data in MyToolkit DataGrid in Universal Windows Platform App在通用 Windows 平台应用程序中自定义 MyToolkit DataGrid 中的特定行数据
【发布时间】:2023-03-25 22:55:02
【问题描述】:

我正在开发 Windows 应用程序。在该应用程序中,我使用的是 MyToolkit 数据网格。我想通过在特定情况下使特定单元格数据闪烁来突出显示数据网格的行。

【问题讨论】:

标签: xaml data-binding uwp


【解决方案1】:

您可以在您的项目中安装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>

lastnameTxtText 不等于“Mike”时,将播放Storyboard。这是渲染图像:

需要注意的一点是初始Background 应该设置为lastnamePanel,否则故事板将无法播放。

【讨论】:

  • 谢谢。我实现了这段代码。但这仅对列有价值。我想知道,通过给出特定条件,闪烁效果应该出现在具有多列的整行中。
  • @Pinky,你介意在后面的代码中这样做,而不是像我的示例中那样使用数据绑定吗?你的具体情况是什么?
  • @GraceFeng-MSFT 效果仅适用于第一行,过滤条件无法正常工作。请您分享一些示例。
猜你喜欢
  • 2019-11-05
  • 2016-02-24
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
相关资源
最近更新 更多