WPF DataGrid - highlight new rows when inserted into datagrid

浪尽此生 提交于 2019-12-05 07:54:31
JPProgrammer

While working on another issue I found something that helped me solve this problem. The solution in Method 1 is very close, it was just a matter of solving the problem of the seemingly random other rows also being highlighted at seemingly random times. The problem was container recycling (more information in this question: WPF Toolkit DataGrid Checkbox Issues).

Anyways, all I had to do was add the following tag to my datagrid:

VirtualizingStackPanel.VirtualizationMode="Standard"

And then I used the same trigger as in method 1:

<DataGridHyperlinkColumn x:Name="OrderID" Binding="{Binding OrderNumber}" 
        Header="Order" SortMemberPath="ciOrderId">
    <DataGridHyperlinkColumn.ElementStyle>                                
        <Style TargetType="TextBlock">
            <Setter Property="Background" Value="Transparent"/>
            <EventSetter Event="Hyperlink.Click" Handler="OrderNumber_Click" />
            <Style.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation 
                                Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" 
                                Duration="00:00:03" 
                                From="Red" To="Transparent" />
                        </Storyboard>                                                
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>

Now I'm able to highlight new rows as they are inserted into my datagrid. Very useful!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!