❔ Dynamically adding xaml code from 1 page to another pages xaml code
I'm working on a simple barbershop application that let's people make appointments etc. At the moment i have a home page, from where you can press a button that opens a login page, after successfully logging in, i want to dynamically add xaml code into the home.xaml from the login.xaml.cs, but i can't access the elements of home.xaml.
21 Replies
You can't access it because you didn't add a
btnHomeLogin
control
But instead of adding btns dynamically, when no switch between two views?the btnHomeLogin is already there in the XAML, it's only used to to get the position where the new button should be placed
And do you mean making another page where the new button is already made in the xaml? I suppose that could work
Is the only difference just a single button?
Or do the two views differ a lot?
Can you show where do you add in XAML?
1 button and a label that welcomes the current user, that's it
to give you an idea, it's just supposed to add a button next to the login one, and maybe change the content of the login button to logout
The code here would get executed when the user clicks login right?
Yes
But because it's in login.xaml.cs it can'tt access the home.xaml
Okay...I'm really confused about how you're structuring your code, you have
btnHomeLogin
in what I assume home.xaml
and you have btnInLoggen
in login.xaml
?Yes, btnHomeLogin is a login button on the homescreen to open up the login page, and btnInloggen is the button on the login page to actually login
Okay, you can pass a callback from home page to the login page, and invoke it in the login page after the user logs in
Though if you can re-architecture the app and go for MVVM it would be better in the long run
what's MVVM?
ah right, Model view viewModel, i'll take a look at it but i'm short on time so prob not going to do that rn
Could you explain the callback some more? how would that look like?
How are you showing the login view from home?
i'm working with a frame
and pages
1. Declare an event in Login view
2. Subscribe to the event from home view
3. Execute the event when the user logins
So i've added this in home.xaml.cs
now how do i activate this from the login.xaml.cs
You need an event, an to subscribe the new method you declared to that event, then excute the event from login.xaml.cs
I'm a bit new to this, could i DM you?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.