I have a button, which calls a method that populates a List<string> with paths to images. I am trying to update a Windows 8 app each time this method is called to show all of the images produced.
Currently it will not show anything, despite simply hardcoding the image path into the List<string>
My XAML code to display the images is :
<ItemsControl ItemsSource="{Binding Path=test}" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="5"
HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
And in the Xaml.cs :
public sealed partial class MainPage : TestApp.Common.LayoutAwarePage
{
public List<string> test = new List<string>();
public MainPage()
{
test.Add("C:\\Users\\user\\Pictures\\image.jpg");
this.InitializeComponent();
}
}
What have I done wrong/needs to be changed here ? Thanks very much :).
You need to set the DataContext of your MainPage. Put this on your MainPage xaml.
EDIT: You need to have a property on your code-behind, not a field: