Reputation: 80
I am making a Panorama Windows Phone 8 app. This is the first time I have actually used one in an app.
I am having problems showing the data in runtime. Instead I am only seeing a list:
RuntimeOne RuntimeTwo RuntimeThree etc..
I don't have a clue what has happened, it worked the other day. I am going into the SampleData folder and changing LineOne, LineTwo, LineThree, etc but it's not doing anything when I deploy the app to the Windows Phone Emulator.
Upvotes: 0
Views: 177
Reputation: 23764
What's happening is that there are two different sets of data, and the DataContext
at runtime is different from design time.
The data that you see in design mode ('design one', 'design two') is
stored in MainViewModelSampleData.cs
, so changing that doesn't affect
the runtime experience.
The data at runtime is coming from the LoadData
method in
MainViewModel.cs
At the top of MainPage.xaml
, you'll see
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
and the "d" namespace here is a mnemonic for 'design'. If you look at the sample data XAML file, you'll notice it declares a class called MainViewModel
with a collection of Items
.
At runtime, MainViewModel.cs
(specifically the LoadData
method) adds items one by one to the Items
property of the MainViewModel
class, and that class is in turn set to be the runtime DataContext
in the constructor of MainPage
The panorama control itself has markup like
<phone:LongListSelector Margin="0,0,-22,0" ItemsSource="{Binding Items}">
so it's expecting to see a collection called Items
on whatever the current DataContext is, and the fact two different data contexts are in play explains what you're seeing.
The data binding magic is incredibly cool and powerful, but sometimes does leave you scratching your head.
Upvotes: 1