So I have tried following UWP Accessing Frame for page navigation through Usercontrol an Object? But I get a nullpointer.
I have a mainpage with a splitview, frame and a hamburger menu. From here I control the pages that are loaded into the frame.
I also have a profile view and i want to invoke a new view when the user clicks a button. Let me add the code:
MainPage:
public sealed partial class MainPage : Page
{
Profile profile = new Profile();
public MainPage()
{
this.InitializeComponent();
MyFrame.Navigate(typeof(Financial));
BackButton.Visibility = Visibility.Collapsed;
Title.Margin = new Thickness(68,0,0,0);
profile.OnNavigateParentReady += OnCreateUser;
}
....
public void OnCreateUser(object sender, RoutedEventArgs e)
{
if (MySplitView.Content != null)
((Frame)MySplitView.Content).Navigate(typeof(CreateUser));
Title.Text = "Create User";
BackButton.Visibility = Visibility.Visible;
Title.Margin = new Thickness(0, 0, 0, 0);
}
}
And profile:
public sealed partial class Profile : Page
{
public delegate void MyEventHandler(object source, RoutedEventArgs e);
public event MyEventHandler OnNavigateParentReady;
private string _profileName;
private string _password;
private Dictionary<string, string> usersDictionary = new Dictionary<string, string>();
public Profile()
{
this.InitializeComponent();
usersDictionary.Add("Casper", "12345");
}
private void Login_Click(object sender, RoutedEventArgs e)
{
_profileName = ProfileName.Text;
_password = PasswordBox.Password;
if (usersDictionary.ContainsKey(_profileName))
{
if (usersDictionary[_profileName] == _password)
{
ProfileName.Text = "LOGIN SUCCES!";
}
}
else
{
}
}
private void CreateUser_Click(object sender, RoutedEventArgs e)
{
OnNavigateParentReady(sender, e);
}
}
I can change the frame with no problem using Frame.navigate but I want to edit the title as well as margin and all other OnCreateUser does. How do I go about that?
EDIT: I should say that i get a nullpointer on this line: OnNavigateParentReady(sender, e);