0
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>

なぜこれが機能しないのですか?私はここで本当に迷っています。リストビューに追加するアイテムの横に画像を追加しようとしています。たとえば、「画像」|「Microsoft」などです。ありがとうございます。

4

2 に答える 2

0

まず、ImageChannel クラスは次のようになります。

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

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

次に、コード ビハインドで、必要に応じて ImageChannel オブジェクトのリストを作成します。

List<ImageChannel> imageChannel = new List<ImageChannel>();
imageChannel.Add(new ImageChannel()
{
  ImagePath = "image path here"
});

次に、ImageChannel List オブジェクトを ListView の itemsSource プロパティに割り当てます。

myListView.itemsSource = imageChannel;

xaml の ListView コントロールは次のようになります。

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

これはうまくいくはずです。

于 2013-06-17T15:34:29.067 に答える