✅ Issue with Triggering View Change in Avalonia using C#
Hello 👋,
I'm facing an issue in C# with Avalonia, and I could use some help. My current code allows me to change the view (usercontrol) in my MainWindow.axaml, but I'm having difficulties triggering this change from a button inside another view (usercontrol), (). Could someone help me troubleshoot this problem?
Part of my code in MainWindow.axaml.cs related to the view change :
Relevant code for this from my MainWindow.xaml :
I'm not entirely sure where the issue is coming from because it was working before. I'm not sure if it's related, but this happened after an update to Avalonia and the libraries in my project. I can't say for certain if that's the cause because I haven't touched the code or the software after doing that update
If my issue isn't clear, I can try to explain it better and even create a 'diagram' if needed
14 Replies
GitHub
GitHub - SirRufo/so-77657479-PageNavigation: Example for stackoverflow
Example for stackoverflow. Contribute to SirRufo/so-77657479-PageNavigation development by creating an account on GitHub.
Thank you, I'll look into that right away.
Sorry, but that doesn't help me much.
Why not?
Because my issue is simply that I can't change the displayed user control from another user control that is already displayed. If I click on buttons that change the user control directly from the main window, it works perfectly.
Yes, and my project shows you how to solve that issue
Oh, sorry. Do you have the part of the code that corresponds to what I want to do, or it's okay, I'll look for it.
In the folder Navigation, but it is not a ready to use solution for you
but it should put you on the right track how to solve it
Thank you for everything, I will try to implement that.
Hi,
So I took an example from your code, and I just have two errors that I can't resolve in my
AvaloniaNavigationService.cs
- Cannot resolve symbol 'MainWindow' | Line : var window = (Window)Avalonia.Application.Current.MainWindow;
- Cannot resolve symbol 'IQueryAttributable' | Line: if (instance is IQueryAttributable attributable)
- 📂 Navigation
- AvaloniaNavigationService.cs
- INavigationService.cs
- QueryPropertyAttribute.cs
- Routing.cs
My codes :
AvaloniaNavigationService.cs
INavigationService.cs
QueryPropertyAttribute.cs
Routing.cs
MainWindow.axaml.cs
GitHub
so-77657479-PageNavigation/WpfApp/Navigation/IQueryAttributable.cs ...
Example for stackoverflow. Contribute to SirRufo/so-77657479-PageNavigation development by creating an account on GitHub.
A quick search for
avalonia get mainwindow
shows https://github.com/AvaloniaUI/Avalonia/issues/3418#issuecomment-732779247GitHub
Where is Application.Current.MainWindow ? · Issue #3418 · AvaloniaU...
I'm upgrading from 8.0 to 9.0 and MainWindow property from Application.Current no longer exist. Why has it been removed and what's the replacement? For me it was an easy way to show dialogs...
Thank you for your help, I succeeded and it works perfectly
$close
Use the /close command to mark a forum thread as answered
Ihope you noticed that you can not only navigate but also can send values to the navigation target declared by attributes or implementing the
IQueryAttributable
😉