Hello,
Welcome to Microsoft Q&A.
The instance of SettinsPage
created in MainPage::MainPage()
is not the instance of SettingsPage
contained by frame SettingsHolder
. Therefore, the statement s->ParentMainPage = this;
does not work for the instance of SettingsPage
contained by frame SettingsHolder
and the ParentMainPage
is null.
You could initiate the value of ParentMainPage
in OnNavigatedTo()
method with the parameter e which contains the parameter passed from Frame.Navigate(Type,Object) method.
For example:
MainPage.xaml.cpp
//Show the SettingsPage page in frame SettingsHolder by using Navigate method
SettingsHolder->Navigate(TypeName(SettingsPage::typeid),this);
SettingsPage.xaml.h
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
SettingsPage.xaml.cpp
void AccessViolation::SettingsPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)
{
MainPage^ mainPage = (MainPage^)e->Parameter;
if (mainPage != nullptr)
{
ParentMainPage = mainPage;
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.