Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在listview metro应用程序上添加图像 公共类图像频道 { 公共字符串ImagePath{get;set;} 公共图像源图像 { 得到 { 返回新的位图图像(新的Uri(“ms appx://”+this.ImagePath)); } } 公共频道列表 { 得到 { 返回新列表() { 新建ImageChannel(){ImagePath=“/Assets/image.png”}; //其他图像 } } }_Listview_Windows 8_Windows Runtime_Microsoft Metro_Windows Store Apps - Fatal编程技术网

在listview metro应用程序上添加图像 公共类图像频道 { 公共字符串ImagePath{get;set;} 公共图像源图像 { 得到 { 返回新的位图图像(新的Uri(“ms appx://”+this.ImagePath)); } } 公共频道列表 { 得到 { 返回新列表() { 新建ImageChannel(){ImagePath=“/Assets/image.png”}; //其他图像 } } }

在listview metro应用程序上添加图像 公共类图像频道 { 公共字符串ImagePath{get;set;} 公共图像源图像 { 得到 { 返回新的位图图像(新的Uri(“ms appx://”+this.ImagePath)); } } 公共频道列表 { 得到 { 返回新列表() { 新建ImageChannel(){ImagePath=“/Assets/image.png”}; //其他图像 } } },listview,windows-8,windows-runtime,microsoft-metro,windows-store-apps,Listview,Windows 8,Windows Runtime,Microsoft Metro,Windows Store Apps,为什么这不起作用?我在这里真的迷路了。我只是想在列表视图中添加的项目旁边添加一个图像,例如“image”|“Microsoft”等。。谢谢 您的代码存在一些问题 首先,将图像属性的声明从 public class ImageChannel { public string ImagePath { get; set; } public ImageSource Image { get {

为什么这不起作用?我在这里真的迷路了。我只是想在列表视图中添加的项目旁边添加一个图像,例如“image”|“Microsoft”等。。谢谢

您的代码存在一些问题

首先,将图像属性的声明从

public class ImageChannel
    {
        public string ImagePath { get; set; }

        public ImageSource Image
        {
            get
            {
                return new BitmapImage(new Uri("ms-appx://" + this.ImagePath));
            }
        }

        public List<ImageChannel> ImageChannels
        {
            get
            {
                return new List<ImageChannel>() 
           {
              new ImageChannel() { ImagePath="/Assets/image.png" }};
                // the other images
            }

        }
    }

<ListView ItemsSource="{Binding ImageChannels}" Margin="222,10,340,140">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Image  Height="113" Source="{Binding}" Stretch="None"/>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

ImageChannel属性get访问器的实现将在每次访问时创建列表。在ImageChannel类中声明并初始化list的成员列表,然后在get访问器中返回,这样做更有意义

Image.Source的XAML代码中的绑定不完整。您需要指明要将其绑定到什么

public BitmapImage Image


如果您解决了这些问题,您应该离实现这一目标更近了。

首先,您的ImageChannel类应该如下所示:

<Image Height="113" Source="{Binding Image}" Stretch="None" />
然后,在代码隐藏中,根据需要创建ImageChannel对象列表:

public class ImageChannel
{
   public string ImagePath { get; set; }

   public BitmapImage Image
   {
       get
       {
          return new BitmapImage(new Uri("ms-appx://" + this.ImagePath));
       }
   }
}
xaml中的ListView控件应该如下所示

myListView.itemsSource = imageChannel;


这应该适合您。

ImageChannel是您的DataContext吗?
List<ImageChannel> imageChannel = new List<ImageChannel>();
imageChannel.Add(new ImageChannel()
{
  ImagePath = "image path here"
});
myListView.itemsSource = imageChannel;
<ListView x:Name="myListView" Margin="222,10,340,140">
      <ListView.ItemTemplate>
            <DataTemplate>
                 <Image  Height="113" Source="{Binding Image}" Stretch="None"/>
             </DataTemplate>
       </ListView.ItemTemplate>
</ListView>