我正在尝试在Windows Phone 8.0 c#中创建一个小的.png图像的下拉列表,它不起作用!请帮助!
我从Win Phone的工具箱参考中选择了一个ListPicker!
以下是XAML代码:
<toolkit:ListPicker Name="ListPicker_AdaugarePDI_Image" Grid.Row="0" Width="70" Margin="0,0,0,0" Background="blue">
<ItemsControl ItemsSource="{Binding imageList}" Height="30">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</toolkit:ListPicker>
然后,在我写的inialization代码中:
string directory = @".\Resources\imagini1";
List<Image> imageList = new List<Image>();
foreach (string fileImage in System.IO.Directory.GetFiles(directory, "*.png"))
{
Image img = new Image();
System.Windows.Media.Imaging.BitmapImage source = new System.Windows.Media.Imaging.BitmapImage();
source.UriSource = new Uri(fileImage, UriKind.Relative);
img.Source = source;
img.Height = 20;
img.Width = 20;
imageList.Add(img);
}
ListPicker_AdaugarePDI_Image.ItemsSource = imageList;
我没有编译错误!图片加载到代码中,我用断点检查,但ListPicker中没有可视化表示!
我应该尝试使用ListPicker以外的其他控件吗?
先谢谢你了!
Bogdy19ro
答案 0 :(得分:0)
以下是对您的代码的修复:
以下是XAML代码:
<toolkit:ListPicker Name="ListPicker_AdaugarePDI_Image" Grid.Row="0" Width="70" Margin="0,0,0,0" Background="blue">
<ItemsControl" Height="30">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Source}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</toolkit:ListPicker>
这是c#代码
string directory = @".\Resources\imagini1";
List<Image> imageList = new List<Image>();
foreach (string fileImage in System.IO.Directory.GetFiles(directory, "*.png"))
{
Image img = new Image();
System.Windows.Media.Imaging.BitmapImage source = new System.Windows.Media.Imaging.BitmapImage();
source.UriSource = new Uri(fileImage, UriKind.Relative);
img.Source = source;
img.Height = 20;
img.Width = 20;
imageList.Add(img);
}
ListPicker_AdaugarePDI_Image.ItemsSource = imageList;