I've been trying to create a custom DataTemplate for ItemSource with the help of .NET MAUI Shell search documentation, but nor the XAML and C# code are not applying the custom template. I am running the code on winUI.
The code I've been trying to accomplish this with:
Inside the ContentPage where the SearchHandler is shown:
<Shell.SearchHandler>
<controls:TagSearchHandler Placeholder="Enter search term"
ShowsResults="true">
<controls:TagSearchHandler.ItemTemplate>
<DataTemplate>
<HorizontalStackLayout Padding="10">
<Label Text="{Binding TagName}"
Margin="0,0,10,0" />
<Label Text="Test" />
</HorizontalStackLayout>
</DataTemplate>
</controls:TagSearchHandler.ItemTemplate>
</controls:TagSearchHandler>
</Shell.SearchHandler>
TagSearchHandler.cs, inside OnQueryChanged
protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
// Filter data based on the newText
var filteredData = new List<DataHolderClass> { /*populate*/ }; ItemsSource = filteredData;
// Set the ItemSource
ItemsSource = filteredData;
}
The TagSearchHandler is using DataHolderClass
public class DataHolderClass: ObservableObject
{
public string TagName { get; set; }
...
}
However by only using this, the SearchHandler displays namespace with class name. SearchHandler results image
Am I missing something?