Dependency Property in HiloPage

Dec 20, 2013 at 5:40 PM
Edited Dec 20, 2013 at 7:22 PM

I am trying to learn how to write WSApps and I am using the Hilo app as my reference app. I am having a problem with the _hiloDataContextProperty concept in my app. I feel like I know the purpose of the DP: attach and detach navigation handlers that can delegate to the VM. However, when I try to implement this pattern in my app, I get an access violation at the SetBinding call in the BasePage constructor. I have been banging my head on this for several hours now and feel like I must be missing something very obvious.

class snippet:
        static property Windows::UI::Xaml::DependencyProperty^ DwfViewerDataContextProperty // was HiloDataContextProperty
            Windows::UI::Xaml::DependencyProperty^ get();
        static void OnDwfViewerDataContextPropertyChanged(Windows::UI::Xaml::DependencyObject^ element, Windows::UI::Xaml::DependencyPropertyChangedEventArgs^ e);
creating the DP:

static TypeName DwfBasePageTypeName = { "DwfViewer.DwfBasePage", TypeKind::Metadata };
static TypeName objectTypeName = { "Object", TypeKind::Primitive };

static DependencyProperty^ _dwfViewerDataContextProperty =
        ref new PropertyMetadata(
            ref new PropertyChangedCallback(&DwfBasePage::OnDwfViewerDataContextPropertyChanged)
In the constructor:
    SetBinding(DwfViewerDataContextProperty, ref new Binding()); // ACCESS VIOLATION
At the SetBinding call, I always receive an access violation reading memory location 0x00000000. I have traced through the debugger, and I know that the DependencyProperty is being created first, and that the DwfViewerDataContextProperty in SetBinding is returning the _dwfViewerDataContextProperty before the access violation happens.

Any suggestions on what I am doing wrong here?

Jan 2, 2014 at 6:05 PM
Hi Mike,

Comparing Hilo's code with yours I don't see any difference between your definition of the DependencyProperty and Hilo's that could be causing the access violation.
It could be possible that whatever is causing it might be in the getter / setter of the property or in the OnDwfViewerDataContextPropertyChanged callback.
Is there anything in there that is different from Hilo's implementation?


Damian Cherubini
Jan 2, 2014 at 8:29 PM
Thanks for looking Damian. I don't see anything different at this point. When I step through, I can see the DP is created first, then the constructor. It tries to make the call to SetBinding. On stepping through, SetBinding invokes the getter for the DP, I can see that it isn't null and successfully returns to continue with SetBinding. At that point I get the access violation. I put a breakpoint in the callback and it is never called. I traced through HILO and it seemed that the SetBinding call was completed before the callback is hit.

So still at a loss with this. I might try and start a brand new project and see if things will behave better.

Thanks for checking it out.
Jan 5, 2014 at 11:36 PM
Just a little update on this ...

I built up a reference app based on HILO in VS2013 targeting Win8.1. The reference app only contains infrastructure that is being demonstrated by HILO. At the SetBinding call, I get the exception.

I decided to try and build up a reference app targeting Win8 in VS2012. I setup a blank app and then copied over the HILO infrastructure classes that support the infrastructure. It doesn't crash at the SetBinding call.

I then made a copy of the project and opened it in the VS2013 and it doesn't crash on the SetBinding call.

I then retarget the copy made previously to Win8.1 and now it crashes on the SetBinding call.

If anybody has insight to this, it would be appreciated ...

Jan 8, 2014 at 2:51 PM
Hi Mike,

I didn't know you were trying to use this in a Windows 8.1 application. As far as I know, hilo was developed before 8.1 was released and there might be some changes between Windows 8 and 8.1 that could be related to this issue.
As a quick test I tried retargeting the entire Hilo C++ solution to Window 8.1 and it throwed the same access violation exception regarding the SetBinding method during runtime. Therefore, it doesn't seem to be a problem with your solution but that this code doesn't works for Windows 8.1.


Damian Cherubini
Jan 8, 2014 at 3:23 PM
Thanks Damian for looking at it. At least I know now that I am not way out in left field on this and I can work around it.
I admit that I am surprised that something that runs in 8 wouldn't run in 8.1.

Thanks again for your help.
Jan 10, 2014 at 5:21 PM
Hi again,

Just as a quick follow up, it seems the development team is aware that there are issues when trying to migrate the solution to Windows 8.1 and is looking into them.
This thread contains another issue that appears when trying to retarget the project:

Damian Cherubini
Jan 12, 2014 at 5:26 AM
Thanks Damian,

Appreciate all the help. I think I will be learning a lot from all of this. :)
Feb 6, 2014 at 6:36 AM
I have an application based on Hilo on the Windows Store too,
Everything worked fine on Windows 8, I tried to migrate it to Windows 8.1.

I changed the LayoutAwarePage to the NavigationHelper to remove the warnings,

but I have the same problem with
MyAppPage::MyAppPage() //Same as the HiloPage.h/.cc
  // ...
  SetBinding(MyAppPage::MyAppDataContextProperty, ref new Binding() ); 
The crash is from vccorlib120d_app.dll, violation reading memory location 0x00000000.

Do you have any workaround for the HiloPage ?

Thanks a lot,

Feb 6, 2014 at 4:30 PM
Hi Vincent,

Unfortunately I don't have a work around for it. In my case, I didn't really need to target 8.1 so I just left it at 8.