public class Item : INotifyPropertyChanged
{
publicevent PropertyChangedEventHandler PropertyChanged;
protectedvirtual void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged !=null)
{
this.PropertyChanged(this, newPropertyChangedEventArgs(propertyName));
}
}
privatestring _Title = string.Empty;
publicstring Title
{
get
{
return this._Title;
}
set
{
if (this._Title != value)
{
this._Title = value;
this.OnPropertyChanged("Title");
}
}
}
privatestring _Subtitle = string.Empty;
publicstring Subtitle
{
get
{
return this._Subtitle;
}
set
{
if (this._Subtitle != value)
{
this._Subtitle = value;
this.OnPropertyChanged("Subtitle");
}
}
}
privateImageSource _Image = null;
publicImageSource Image
{
get
{
return this._Image;
}
set
{
if (this._Image != value)
{
this._Image = value;
this.OnPropertyChanged("Image");
}
}
}
publicvoid SetImage(Uri baseUri, String path)
{
Image = new BitmapImage(newUri(baseUri, path));
}
privatestring _Category = string.Empty;
publicstring Category
{
get
{
return this._Category;
}
set
{
if (this._Category != value)
{
this._Category = value;
this.OnPropertyChanged("Category");
}
}
}
}
public classStoreData
{
private Item item;
private Uri _baseUri = newUri("ms-appx:///");
public StoreData()
{
CreateItem("Royma1", "Images/Royma1.jpg");
CreateItem("Royma2", "Images/Royma2.jpg");
CreateItem("Royma3", "Images/Royma3.jpg");
CreateItem("Fuji1", "Images/Fuji1.jpg");
CreateItem("Fuji2", "Images/Fuji2.jpg");
CreateItem("Fuji3", "Images/Fuji3.jpg");
CreateItem("Tesga1", "Images/Tesga1.jpg");
CreateItem("Tesga2", "Images/Tesga2.jpg");
CreateItem("Tesga3", "Images/Tesga3.jpg");
CreateItem("Tesga4", "Images/Tesga4.jpg");
CreateItem("Tesga5", "Images/Tesga5.jpg");
}
public void CreateItem(string title,stringpath)
{
item = newItem();
item.Title= title;
item.Subtitle = "Tennis" + title;
item.SetImage(_baseUri, path);
item.Category = "Category:" +"\r\n"+ title.ToUpper();
Collection.Add(item);
}
publicObservableCollection<Item> Collection= newObservableCollection<Item>();
}
public sealed partialclass MainPage : Page
{
private StoreData storeData = null;
public MainPage()
{
this.InitializeComponent();
storeData= new StoreData();
//直接使用StoreData中的Collection集合作為GridView的ItemsSource
ItemGridView.ItemsSource = storeData.Collection;
////按照字母顯示GridView
//List<GroupInfoList<object>>dataLetter = storeData.GetGroupsByLetter();
//dataSource.Source = dataLetter;
//按照目錄顯示GridView
//List<GroupInfoList<object>>dataCategory = storeData.GetGroupsByCategory();
//dataSource.Source = dataCategory;
//SemanticZoom
//(semanticZoom.ZoomedOutView as ListViewBase).ItemsSource =dataSource.View.CollectionGroups;
}
private void ItemGridView_ItemClick(objectsender, ItemClickEventArgs e)
{
}
private void GetGridViewItemInfo_Click(objectsender, RoutedEventArgs e)
{
}
}
<GridViewx:Name="ItemGridView"
BorderBrush="Blue"BorderThickness="3"
VerticalAlignment="Top"HorizontalAlignment="Left"
ScrollViewer.VerticalScrollBarVisibility="Auto"ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectionMode="Multiple"Background="Transparent"
IsItemClickEnabled="True"ItemClick="ItemGridView_ItemClick"
CanDragItems="True" CanReorderItems="True"AllowDrop="True"
>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<!--不能為VariableSizedWrapGrid-->
<WrapGridOrientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left"Background="Black">
<StackPanel Orientation="Horizontal"Margin="5,5,0,5">
<ImageSource="{Binding Image}" Height="300" Width="300"VerticalAlignment="Center" Margin="0,0,0,0"/>
<StackPanelMargin="0,0,0,0" Orientation="Vertical">
<TextBlock Name="title"TextWrapping="Wrap" Width="100" Foreground="White" FontSize="15"VerticalAlignment="Center" Text="{BindingTitle}"
HorizontalAlignment="Left" FontFamily="Segoe UI"/>
<TextBlock Name="category"TextWrapping="Wrap" Width="100" Foreground="Beige" FontSize="15"VerticalAlignment="Center" Text="{BindingCategory}"
HorizontalAlignment="Left" FontFamily="Segoe UI"/>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<StyleTargetType="GridViewItem">
<Setter Property="BorderBrush"Value="Blue" />
<SetterProperty="BorderThickness" Value="2" />
<SetterProperty="HorizontalContentAlignment" Value="Center"/>
<SetterProperty="VerticalContentAlignment" Value="Center"/>
<Setter Property="Background"Value="Transparent"/>
</Style>
</GridView.ItemContainerStyle>
</GridView>