49 Replies
I created a NavigationStore to save the currentViewModel
the problem is
Everything works fine until this part
When the navigationStore calls the OnCurrentViewModelChanged() function
The logs is right, shows the new view to be displayed
but the function OnPropertyChanged does not make any change
Im binding this way
your code shown above doesnt include any
OnPropertyChanged
listeners
nvm, hidden in the baseclass ofc
my base class extend the mvvm toolkit
that already have the listener for OnPropertyChanged
what about if you try binding directly to the
_navigationStore
's CurrentViewModel
?
you'd have to make it public obviously...what do you mean?
ohh
nevermind
i got
i think i cant do it, cuz my dataContext is set to the mainViewModel
not to NavigationStore
and then
but mainViewModel has a navigation store in it.
{Binding NavigationStore.CurrentViewModel}
If that doesn't work then try putting those data templates into the ContentControl
's resources. Maybe it isn't finding them in your window for some reason?when i initialize its blank now
In your window put
d:DataContext="{d:DesignInstance MainViewModel}"
so that you can see any binding errors
then you won't get those 3 dotted lines under some binding expressions
... unless the binding is invalid
It works the same ways as before
okk
Also try moving those data templates into the ContentControl's resources instead
it might not be finding the windows' resources for some reason
If that still doesn't work then maybe you aren't even setting the windows' data context somehow?
sry, but i dont get it, what do u mean with ContentCOntrol's resources, im kinda new in wpf
In your window you have
Window.Resources
, and anything inside that, are resources that the window and any of its children have access tooI do
But the ContentControl might not be able to access them for some reason, so replace the content control with
If that also doesn't work then i'm not sure based on the code you provided
yeah doesnt work
Unless the DateTemplate types don't match up with the type that
CurrentViewModel
becomes
that could also be a problemas my experience, i thinks its a update in main windows problem
as I said this functions is called when a ViewModel is changed
but the new viewModels does not update in .xaml
this is my class NavigationStore
Try changing ContentControl to ContentPresenter
I know that calling the function this way its bad
I tried to do it with an event
I looked at one of my old projects and it uses ContentPresenter, but rarely ContentControl
but does not work
ok
doesnt work
why its soo difficult to switching between views using mvvm pattern?
In your xaml are you still binding to
CurrentViewModel
or to NavigationStore.CurrentViewModel
?NavigationStore.CurrentViewModel
and you're using the MainViewModel code i provided?
yes
It's not working because you're creating a new instance of your MainViewModel each time the CurrentViewModel changes
if you use that instead, then it should work
as long as your windows' data context is set to an instance of
MainViewModel
does not work
i also added the
Are you sure your windows' DataContext is set to an instance of MainViewModel?
yeah
I dunno then... something must be wrong with your WPF install if binding doesn't work
do you have tutorial i that i can follow?
not really...
i tried a lot tutorials in yt
nothin works
is your project on github?
i can put it
to you take a look
if you do that then i can look
hold on a sec please
GitHub
GitHub - Snitrxm/ATM-System-MVVM
Contribute to Snitrxm/ATM-System-MVVM development by creating an account on GitHub.
here u go
i'll appreciated a lot if you can take a look for me
In your HomeView and AccountView classes, remove the code where you're setting
DataContext
because the data context will already be set to HomeViewModel and AccountViewModel automaticall, because of how data templates work
and then it should work after thatyeah its works
i dunno why
wpf is spooky
thx a lot bro
np
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.