access Viewmodel in header of of SfListview

Hi, 
I want to acces a search-bar in the codebehind.

Here is my code:

xaml:
<syncfusionListView:SfListView x:Name="lsvListView" BackgroundColor="Transparent" ItemSize="200">
            <syncfusionListView:SfListView.HeaderTemplate>
                <DataTemplate>
                    <StackLayout Margin="20,0,20,0">
                        <Label BackgroundColor="Transparent" HeightRequest="15"/>
                        <SearchBar x:Name="sebSearchBar" Placeholder="Suche..." TextColor="#222A2C" TextChanged="SebSearchBarTextChanged" Margin="-15,0,0,0"/>
                        <Label BackgroundColor="Transparent" HeightRequest="15"/>
                    </StackLayout>
                </DataTemplate>
             </syncfusionListView:SfListView.HeaderTemplate>
</syncfusionListView:SfListView>

codebehind:
sebSearchBar.Text="example text"; //this doesn't work

1 Reply 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team February 1, 2021 05:20 AM UTC

Hi Jonas, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Access ListView Header in ViewModel” from our side. We would like to inform you that you should not directly access the UI elements in the ViewModel class. Please refer to the discussion for the same, 
 
But, you can achieve your requirement by binding the SearchBar.Text by using properties. Please refer to the following documentation for data binding in Xamarin.Forms, 
 
Also, the BindingContext for the HeaderTemplate is model class and you can bind the model class property to the SearchBar text as binding to the ItemTempalate elements. Please refer to our user guidance document regarding the same, 
 
If you are not interested in binding, you can get the DataTemplate elements in the code behind using behaviors. Please refer to the following documentation in the link below, 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 


Marked as answer
Loader.
Up arrow icon