简体   繁体   中英

Adding Item to listpicker by loop

I want to add items to listpicker control of toolkit. I am doing this way.

for (int i = 0; i < cstringl.Length; i++)
{
    listPickerCountrySignup.Items.Add(cstringl[i]);
}

and here is MY XAML.

<toolkit:ListPicker x:Name="listPickerCountrySignup" SelectionChanged="listPickerCountry_SelectionChanged" Height="72" HorizontalAlignment="Left" Margin="14,43,0,0" VerticalAlignment="Top" Width="436" FullModeHeader="Select Country" Background="White" BorderBrush="White" Foreground="{StaticResource listPickerBrush}" Style="{StaticResource ListPickerStyle1}">
                        <toolkit:ListPicker.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Country}" Width="300" />
                                </StackPanel>
                            </DataTemplate>
                        </toolkit:ListPicker.ItemTemplate>
                        <toolkit:ListPicker.FullModeItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/>
                                </StackPanel>
                            </DataTemplate>
                        </toolkit:ListPicker.FullModeItemTemplate>
                    </toolkit:ListPicker>

But its not showing in UI as I have binding in XAML but item I am adding from code behind by loop. No item source binding. How I Can Show Item in That List..

You have to do some data binding.

ObservableCollection<T> ListPickerItems = new ObservableCollection<T>();
for (int i = 0; i < cstringl.Length; i++)
{
    ListPickerItems .Add(cstringl[i]);
}

in Xaml:

<toolkit:ListPicker ItemsSource={Binding ListPickerItems} ... />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM