简体   繁体   中英

WPF Datagrid highlight row and column

Is there a way to programmatically highlight a row and column in the WPF datagrid? I am using the scrollIntoView method to jump to that row and column. I'd like to highlight that row as well to highlight to the user that this is what's important. Thanks!

If you have a business object for whatever is represented in the datagrid, in the DataGrid.RowStyle I would use a DataTrigger bound to a boolean in the object representing the row. Then when you ScrollIntoView you could set this boolean and let XAML handle setting the row color for you. It might get weird because then you would have to reset any other ones set. But I think this could be an easy solution.

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IsSelected}" Value="True">
                <Setter Property="Background" Value="Red" />
            </DataTrigger >
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM