locked
Where is defaultViewModel actually set (Hub template)

    Question

  • As something of a learning process, I'm working my way around the code provided with the Hub template (universal app). Making good progress but there's one aspect is bugging me. Pretty sure this is a 101-type question!

    In Hub.xaml.cs I see the public property DefaultViewModel and that it returns the backing variable defaultViewModel. But I can't see where the backing variable itself (defaultViewModel) is set.

    The NavigationHelper_LoadState() method sets this.DefaultViewModel["Groups"] directly. So, no reference to defaultViewModel there or anywhere else in the file.

    So, if the getter for DefaultViewModel returns defaultViewModel, where and how is the backing variable set?

    Call me slow...

    Mark


    Mark Williams

    Wednesday, August 13, 2014 1:50 AM

Answers

All replies

  • Hi Mark,

    Build the app then click on defaultViewModel and hit F12.  That will bring you to where it is defined.


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Wednesday, August 13, 2014 12:49 PM
    Moderator
  • Thanks for the response, Jeff. I didn't state my question very clearly.

    I am clear on where it's defined. I also see where it's referenced (just one, in the getter for DefaultViewModel). But the bit that is confusing me is where it (defaultViewModel) is SET.

    The definition and the reference (in the aforementioned getter) are the only uses of "defaultViewModel" I can find. So, if the DefaultViewModel is returning this.defaultViewModel, where is the value of this.defaultViewModel actually set?

    By the way, the NavigationHelper_LoadState does largely what I would expect it to so - fetches the data from the JSON sample data file - but that puts it directly into DefaultViewModel["Groups"). Again, no reference to the backing variable, defaultViewModel.

    I'm missing something simple here, I fear.

    Thanks again.

    Mark


    Mark Williams

    Wednesday, August 13, 2014 3:26 PM
  • Making this a little more tangible, scroll down in the screenshot below and see the arrow I inserted. How and where does that specific variable (the backing variable) get set? The only thing that seems to get set anywhere is DefaultViewModel (not the defaultViewModel backing variable).


    Mark Williams

    Wednesday, August 13, 2014 3:43 PM
  • Hi Mark,

    Look up the page you have displayed there:

    private ObservableDictionary defaultViewModel = new ObservableDictionary();
    


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, August 14, 2014 6:21 PM
    Moderator
  • How has nobody suggested he look in the XAML Designer file where <page> specifies the following ..

    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"

    inside the opening brackets of the <Page> element ..

    Possibly that is what he is after?

    Thursday, August 28, 2014 7:52 PM