2013-03-11 86 views
1

如何訪問longlistselector項目。如何訪問Windows Phone 8中的Longlistselector子對象

我的XAML是:

<Grid x:Name="ContentPanel" Grid.Row="1" HorizontalAlignment="Left" Height="Auto" Margin="30,20,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="420"> 
    <phone:LongListSelector Name="longList" HorizontalAlignment="Left" Height="Auto" Margin="0" VerticalAlignment="Top" Width="420"> 
    <phone:LongListSelector.ItemTemplate> 
     <DataTemplate> 
     <Grid Background="Transparent"> 
      <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="210" /> 
      <ColumnDefinition Width="210" /> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
      <RowDefinition Height="160" /> 
      </Grid.RowDefinitions> 
      <Image Name="first" Width="210" Margin="0" Source="{Binding ImageName}" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" /> 
      <Image Name="second" Width="210" Margin="0" Source="{Binding ImageName}" Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Right" /> 
     </Grid> 
     </DataTemplate> 
    </phone:LongListSelector.ItemTemplate> 
    </phone:LongListSelector> 
</Grid> 

我想要得到的圖像的訪問對象第一 & 第二

我需要從包含類的列表中指定這兩個圖像對象的源圖像名稱字符串作爲變量(保存jpg圖像的路徑)連續,然後下兩行到下一行等。

+0

我只需要需要首先設置圖像源。 – Abhishek 2013-03-12 04:17:57

+0

此演示將向您展示如何在WP8中填充longlistselector。http://www.geekchamp.com/articles/the-new-longlistselector-control-in-windows-phone-8-sdk-in-depth – 2013-03-12 07:17:00

回答

0

添加一個新的文件夾,以解決和重命名文件夾爲「模型」

然後添加一個新的類名爲「ImageSourceClass」

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace TestApp.Model 
{ 
    public class ImageSourceClass 
    { 
     public string ImageUrl { get; set; } 

     public ImageSourceClass(string imageUrl) 
     { 
      this.ImageUrl = imageUrl; 
     } 
    } 

    public class ImageData : ObservableCollection<ImageSourceClass> 
    { 
     public ImageData() 
     { 
      Add(new ImageSourceClass("/Assets/Images/Fruits.jpg")); 
      Add(new ImageSourceClass("/Assets/Images/Beignets.jpg")); 
      Add(new ImageSourceClass("/Assets/Images/Dessert.jpg")); 
      Add(new ImageSourceClass("/Assets/Images/Pretzel.jpg")); 
      Add(new ImageSourceClass("/Assets/Images/Shrimp.jpg")); 
      Add(new ImageSourceClass("/Assets/Images/SteakSandwich.jpg")); 
     } 
    } 
} 

MainPage.xaml中

添加下面的命名空間到MainPage.xaml中

注:根據您的解決方案的名稱命名空間可能會有所不同]

的xmlns:爲MyModel = 「CLR命名空間:TestApp.Model」

<Grid x:Name="LayoutRoot" Background="Transparent" > 
<Grid.Resources> 
     <MyModel:ImageData x:Key="imageDatasource"></MyModel:ImageData> 
</Grid.Resources> 
<phone:LongListSelector x:Name="lstRestoItems" ItemsSource="{StaticResource imageDatasource}" LayoutMode="List"> 
    <phone:LongListSelector.ItemTemplate> 
     <DataTemplate> 
      <Image Source="{Binding ImageUrl}" Height="100" Width="100"   HorizontalAlignment="Left"></Image> 
     </DataTemplate> 
    </phone:LongListSelector.ItemTemplate> 
</phone:LongListSelector> 

</Grid> 

我們都做了,現在只是乾淨,重新構建應用程序,然後按F5

相關問題