Unclear how to cleanly implement Search (in XAML with MVVM bindings)
Documentation on this is quite sparse, with only out-of-context C#-implementation examples given like below:
```
this.dataGrid.SearchController.AllowFiltering = true;
this.dataGrid.SearchController.Search(entry.Text);
```
But I'm expecting to be able to do something like this in XAML:
```
<datagrid:SfDataGrid.SearchController>
<datagrid:DataGridSearchController
AllowCaseSensitive="False"
AllowFiltering="True"
CanHighlightSearchText="True"
SearchText="{Binding SearchText, Mode=TwoWay}"
SearchType="Contains" />
</datagrid:SfDataGrid.SearchController>
```
But this gives an error:
Type 'DataGridSearchController' is not usable as an object element because it is not public or does not define a public parameterless constructor or a type converter.
Meanwhile, documentation screenshots show a neatly styled search-bar with all the bells and whistles (next,previous,clear) above the grid, but it's not even clear to me whether this is a built-in control or something I have to create myself..
Further guidance on how to actually use this feature would be much appreciated!
Thank you for your reply,
Given that the DataGrid's Search-functionality currently cannot be set through XAML, would you know of any full code samples that first define the DataGrid in XAML and then configure Search in one of the ways you mentioned?
I couldn't find any examples of this being used in MAUI, which doesn't help my understanding.
Another unanswered question would be about the search-bar itself (taken from docs):
Is this part of the DataGrid-control once Search is correctly configured, or am I expected to create such a control myself?
Kind regards,
Jack
Attachment: DataGridSearchingSample_8ce3fd6b.zip
Hi Muthukumar,
Very insightful answer, and the included sample is very helpful as well!
Based on your sample I have successfully got this working through MVVM (by passing the SfDataGrid instance to the ViewModel through the code-behind).
That setup is not as intuitive as I would have hoped, but once it's configured it works robustly and that's what counts.
Thank you very much!
Kind regards,
Jack
- 5 Replies
- 2 Participants
- Marked answer
-
JS Jack S.
- Dec 7, 2025 07:27 PM UTC
- Dec 11, 2025 06:09 AM UTC