Windows Phone 8.1 Hub Template Project DataContext Binding -


this might stupid question i'm having trouble recreating hub page data binding method used "hub app" template in own windows phone app.

my xaml bound viewmodel class defined public property of page object , works fine long include line:

this.datacontext = *viewmodel object here* 

within onnavigatedto() method.

if comment out line, no data loaded @ runtime. might sound obvious (and question), "hub app" template never assigns object "this.datacontext" in .xaml.cs file. binding ever defined in xaml. missing?

update: added xaml , xaml.cs

xaml

<page datacontext="{binding subject, relativesource={relativesource mode=self}}" d:datacontext="{d:designdata source=sampledata/subjectsampledata.xaml}"> 

xaml.cs

public sealed partial class blankpage1 : page {     public blankpage1()     {         this.initializecomponent();     }      public subject subject { get; set; }      protected override void onnavigatedto(navigationeventargs e)     {         if (e.parameter != null)         {             var subjectname = e.parameter string;              var subject = app.mainviewmodel.subjects.single(item => item.name == subjectname);              if (subject != null)             {                 this.subject = subject;             }              //this.datacontext = this.subject;         }     } } 

the hubapp template defines binding inside xaml:

<page x:class="app1.hubpage" <!-- namespaces --> datacontext="{binding defaultviewmodel, relativesource={relativesource self}}" <!-- rest of code --> 

it's same effect have put in constructor: this.datacontext = defaultviewmodel;.


edit - after comments

your situation little different - binding 'normal' property without inotifypropertychanged, icollectionchanged or other. in template , find binding there defined observabledictionary - when item added/removed such distionary, raises suitable event allows update ui. in case there no such place.

your program works - when page created, hence have bound datacontext, property getter called (put there debug.writeline("getter");) there nothing yet in property ui empty. little later onnavigatedto (put there debug.writeline("navigation event");) called in populate property, ui not notified that, it's not updated.


Popular posts from this blog