C
C#16mo ago
Knoepert

❔ 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
Kouhai
Kouhai16mo ago
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?
Knoepert
KnoepertOP16mo ago
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
Kouhai
Kouhai16mo ago
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?
Knoepert
KnoepertOP16mo ago
1 button and a label that welcomes the current user, that's it
Knoepert
KnoepertOP16mo ago
Knoepert
KnoepertOP16mo ago
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
Kouhai
Kouhai16mo ago
The code here would get executed when the user clicks login right?
Knoepert
KnoepertOP16mo ago
Yes But because it's in login.xaml.cs it can'tt access the home.xaml
Kouhai
Kouhai16mo ago
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?
Knoepert
KnoepertOP16mo ago
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
Kouhai
Kouhai16mo ago
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
Knoepert
KnoepertOP16mo ago
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?
Kouhai
Kouhai16mo ago
How are you showing the login view from home?
Knoepert
KnoepertOP16mo ago
Knoepert
KnoepertOP16mo ago
i'm working with a frame and pages
Kouhai
Kouhai16mo ago
1. Declare an event in Login view 2. Subscribe to the event from home view 3. Execute the event when the user logins
Knoepert
KnoepertOP16mo ago
So i've added this in home.xaml.cs
Knoepert
KnoepertOP16mo ago
now how do i activate this from the login.xaml.cs
Kouhai
Kouhai16mo ago
You need an event, an to subscribe the new method you declared to that event, then excute the event from login.xaml.cs
Knoepert
KnoepertOP16mo ago
I'm a bit new to this, could i DM you?
Accord
Accord16mo ago
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.
Want results from more Discord servers?
Add your server