简体   繁体   English

在Windows Phone 8中制作.png文件的ListPicker

[英]Making a ListPicker of .png files in Windows Phone 8

I am trying to make a kind of dropdown list of little .png images in Windows Phone 8.0 c# and it doesn't work! 我正在尝试在Windows Phone 8.0 c#中制作一种小.png图像的下拉列表,但是它不起作用! Please Help! 请帮忙!

I choosed an ListPicker from the toolkit refrence for Win Phone! 我从Win Phone的工具包参考中选择了一个ListPicker!

Here is the XAML code: 这是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>

Then, in the inialization code i wrote : 然后,在初始化代码中,我写道:

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;

I got no compile error! 我没有编译错误! The pictures are loaded in the code, I checked with breakpoints, but there is no visual representation in the ListPicker! 图片已加载到代码中,我检查了断点,但ListPicker中没有可视表示!

Should I try with another control other than ListPicker? 我应该尝试使用ListPicker以外的其他控件吗?

Thank you in advanced! 谢谢高级!

Bogdy19ro Bogdy19ro

Here is the fix to your code: 这是您的代码的修复:

Here is the XAML code: 这是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>

Here is c# code 这是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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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