Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify that Page navigation does not guarantee that the DataContext is initialized when the Page is loaded #2629

Open
18 tasks
ramezgerges opened this issue Nov 28, 2024 · 3 comments
Labels
kind/consumer-experience Categorizes issue or PR as related to improving the experience of consumers kind/documentation Categorizes an issue or PR as relevant to 3rd party dependencies that are consumed by this project triage/untriaged Indicates an issue requires triaging or verification.

Comments

@ramezgerges
Copy link

What would you like clarification on

Concern?

  • Usage in industry
  • Clarification of capabilities
  • Getting started with Uno
  • Developing with Uno
  • Contributing to the Uno project
  • Publishing your application
  • Support
  • Other (please specify):

For which Platform

  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Anything else we need to know?

@ramezgerges ramezgerges added kind/consumer-experience Categorizes issue or PR as related to improving the experience of consumers kind/documentation Categorizes an issue or PR as relevant to 3rd party dependencies that are consumed by this project triage/untriaged Indicates an issue requires triaging or verification. labels Nov 28, 2024
@ramezgerges
Copy link
Author

cc. Nick

@DevTKSS
Copy link

DevTKSS commented Dec 9, 2024

would like to add the detail, that for the given case it is not set, we can simply forget to use x:Bind beside Navigation, which needs DI if we want to reach the ViewModel.
On the main uno repo and discord was told to do:

Private MainViewModel? ViewModel => (MainViewModel)DataContext;

or:

Private MainViewModel? ViewModel => DataContext as MainViewModel;

but as soon as I try to bind a task like this:
image

no difference if I leave out the Mode, it is throwing a NullReferenceException for the ViewModel! but for things like the simple Title thats not happening at all. Known Issue I heared of would be, twoWay Mode to be complicated, but its the one which is (at least for me) not known to be bugged. So it would be really nice to know how it is working to get the DataContext set in the given case, the navigator fails to do this:
image

the page can not take the parameter because the routemaps are not enabling this to be done and the second code on the screenshot from the docs are doing what I did replicate.
At this point, I would go so far, out of pure desperation, just for getting this ViewModel for the DataContext, to add:

private MainViewModel? ViewModel => DataContext as MainViewModel ?? this.Navigator()?.Get<MainViewModel>();

Because the x:Bind is applyed at this.InitializeComponent(); if I am correct and seems like the DataContext is not set corrctly as expected. But before you do test it, let me tell you, that is not helping this issue at all, still throwing the same issue at the same line. Hopelessly in my opinion.
So when it comes to performance and functionallity of binding to this kind of things where it would be nice, its just not usable...
To solve this, it would be really nice to know what we CAN do, if this happens, if not even the Navigator can pring us this MainViewModel...

@DevTKSS
Copy link

DevTKSS commented Dec 9, 2024

unoplatform/uno#18710 (comment)
Similar issue also mentioned there, no responses only "not use it"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/consumer-experience Categorizes issue or PR as related to improving the experience of consumers kind/documentation Categorizes an issue or PR as relevant to 3rd party dependencies that are consumed by this project triage/untriaged Indicates an issue requires triaging or verification.
Projects
None yet
Development

No branches or pull requests

2 participants