This example introduces Scrollbar Annotations in the WPF GridControl. When the grid loads, its vertical scrollbar displays annotations that indicate the location of search results and selected cells. These visual markers allow users to quickly navigate to relevant data.
The example displays a side panel that lists annotation modes supported by the GridControl. When a user selects a mode, the bound ScrollBarAnnotationMode property updates accordingly:
<dxg:TableView x:Name="myView"
ScrollBarAnnotationMode="{Binding EditValue, ElementName=myListBoxEdit, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
ScrollBarCustomRowAnnotation="MyScrollBarCustomRowAnnotationEventHandler" />The GridControl can display annotations for the following items:
- Focused and selected rows
- Invalid rows and cells
- Search results
To define additional annotations based on custom rules, handle the ScrollBarCustomRowAnnotation event. In this example, the event handler checks the Number property of a row’s data object and displays a custom annotation if the value falls within certain ranges:
void MyScrollBarCustomRowAnnotationEventHandler(object sender, ScrollBarCustomRowAnnotationEventArgs e) {
if (e.Row is not TestData data) return;
int number = data.Number;
if (number > 10 && number < 15)
ShowCustomScrollAnnotation(e, Brushes.LightCoral);
if (number > 2 && number < 4)
ShowCustomScrollAnnotation(e, Brushes.Green);
}
void ShowCustomScrollAnnotation(ScrollBarCustomRowAnnotationEventArgs e, SolidColorBrush brush) {
e.ScrollBarAnnotationInfo = new ScrollBarAnnotationInfo() {
Alignment = ScrollBarAnnotationAlignment.Right,
Brush = brush,
MinHeight = 3,
Width = 10
};
}- MainWindow.xaml (VB: MainWindow.xaml)
- MainWindow.xaml.cs (VB: MainWindow.xaml.vb)
- ViewModel.cs (VB: ViewModel.vb)
- WPF Data Grid – Specify Custom Content for Column Chooser Headers
- WPF Data Grid – Handle Drag and Drop Operations
- WPF Data Grid – Bind to Dynamic Data
(you will be redirected to DevExpress.com to submit your response)
