How to use x:Name of items in listView at codebehind?

后端 未结 4 1909
情书的邮戳
情书的邮戳 2021-01-24 10:27

Is there any way to use x:Name of the stacklayout in listview at code behind in xamarin.forms?

 

        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 11:02

    Because it is a ListView, there may be multiple StackLayouts. So what you need to do is give the ListView an x:Name property, and then you can access the items in the ListView using it's ItemSource property. Like so:

    
        
            
                
                   
                       
                   
                
           
        
    
    

    Then in your code-behind, simply access the items through myListView.ItemsSource.

    If you really need to manipulate an individual StackLayout in the list view, then you should think about setting it up properly using MVVM pattern.

提交回复
热议问题