【问题标题】:Making a ListPicker of .png files in Windows Phone 8在 Windows Phone 8 中制作 .png 文件的 ListPicker
【发布时间】:2018-07-26 21:32:42
【问题描述】:

我正在尝试在 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>

然后,在我写的初始化代码中:

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

【问题讨论】:

    标签: c# windows-phone-8


    【解决方案1】:

    这里是你的代码的修复:

    这是 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      相关资源
      最近更新 更多