我想将项目添加到toolkit的toolpicker控件中。 我这样做。
for (int i = 0; i < cstringl.Length; i++)
{
listPickerCountrySignup.Items.Add(cstringl[i]);
}
这是我的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>
但它没有在UI中显示,因为我在XAML中绑定了但是我从循环后面的代码中添加了项目。没有项目源绑定。我如何在该列表中显示项目..
答案 0 :(得分:1)
你必须做一些数据绑定。
ObservableCollection<T> ListPickerItems = new ObservableCollection<T>();
for (int i = 0; i < cstringl.Length; i++)
{
ListPickerItems .Add(cstringl[i]);
}
在Xaml中:
<toolkit:ListPicker ItemsSource={Binding ListPickerItems} ... />