Is the .Net Maui Listview.Header tag able to contain a label with Text Search and SearchBar control

Ronald Rex 1,671 Reputation points
2024-02-06T18:06:53.23+00:00

Hi Friends, I was wondering is the listview header able to be formatted to contain a Label with text Search followed by a SerachBar. These two elements should be on the same line. Thanks !

Developer technologies | .NET | .NET MAUI
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-02-07T02:11:11.78+00:00

    Hello,

    Yes, Header of type object, specifies the string or view that will be displayed at the start of the list. You can put Label and SearchBar in the Listview.Header's Stacklayout like following code.

     <ListView>
          <ListView.Header>
              <StackLayout Orientation="Horizontal" BackgroundColor="LightGray">
                  <Label Margin="10,0,0,0" VerticalOptions="CenterAndExpand"
             Text="Search"
             FontSize="12"
             FontAttributes="Bold" />
                  <SearchBar/>
              </StackLayout>
          </ListView.Header>
          <ListView.ItemsSource>
              <x:Array Type="{x:Type x:String}">
                  <x:String>mono</x:String>
                  <x:String>monodroid</x:String>
                 
              </x:Array>
          </ListView.ItemsSource>
      </ListView>
    

    For more information, you can refer to this document: Display views in the header and footer

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.