This is my first win 8 store app using XAML, so kind of not sure about few things. I want to bind data to a gridview. To do this, I have a
class Category
{
public int Id { get; set; }
public string CategoryName { get; set; }
public string IconPath { get; set; }
}
in the code behind, i have
protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
Model.Utility util = new Utility();
var categories = util.GetCategoryList(); // this returns List<Category>
this.DefaultViewModel["Items"] = categories;
}
and my xaml is:
<!-- Horizontal scrolling grid used in most view states -->
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.RowSpan="2"
Padding="116,136,116,46"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
SelectionMode="None"
IsSwipeEnabled="false"/>
But I dont see any data when I run the app. Where am i doing it wrong?
The Standard250x250ItemTemplate binds to the properties Title, SubTitle and Image by default. Unless you have updated the template, your Category class does not have those properties to the ItemTemplate does not have anything to display. I suspect there are databinding errors VS when you debug the apps saying the Title,SubTitle and Image properties cannot be found.
To correct this, right-click on the GridView, selected Edit Additonal Templates, Edit Generated Items (ItemTemplate), Edit a Copy and update the template to bind the correct elements to the property names on your class.