I do not know how many columns and column name in a listview?

mc 3,221 Reputation points

I use a ListView But I do not know how many columns is in it it is dynamic.

the only know column is Id

I can set the binding of Id

how to set others binding?

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,193 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 58,496 Reputation points Microsoft Vendor



    how to bind it to Label?

    You can bind it with  <Label Text="{Binding .}"></Label> diretly like following layout.

     <ListView x:Name="mysl">
                            <Label Text="{Binding .}"></Label>

    Here is background code.

    public NewPage1()
           ObservableCollection<string> Dates = new ObservableCollection<string>();
           Dates.CollectionChanged += Dates_CollectionChanged; ;
            for (int i = 0; i < 10; i++)
            mysl.ItemsSource = Dates;
     private void Dates_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            var values=sender as ObservableCollection<string>;
            var valuecount=values.Count;
            var name = e.NewItems;

    You can use ObservableCollection<string> instead of string[].

    And add CollectionChanged delegate, when you add or remove item in the ObservableCollection, Dates_CollectionChanged method will be execute. You can get count by values.Count;, get the added column name by e.NewItems;

    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.

0 additional answers

Sort by: Most helpful