Hello,
==========Update=========
how to bind it to Label?
You can bind it with <Label Text="{Binding .}"></Label>
diretly like following layout.
<ListView x:Name="mysl">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding .}"></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Here is background code.
public NewPage1()
{
InitializeComponent();
ObservableCollection<string> Dates = new ObservableCollection<string>();
Dates.CollectionChanged += Dates_CollectionChanged; ;
for (int i = 0; i < 10; i++)
{
Dates.Add(i.ToString());
}
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.