❔ Onpropertychanged
Hello, i'd like to trigger
OnpropertyChanged(nameof(CurrentProgramBending))
from this code :
How i'm i supposed to do because i've already set OnpropertyChanged(nameof(CurrentProgramBending))
inside ListingProgramBendingViewModel
but i can't retrieve the event inside ProgramBendingSelectViewModel
Here is the original declaration inside ListinProgramBendingViewmodel
12 Replies
You need your "outer" viewmodel
ProgramBendingSelectViewModel
to fire the OPC eventAvoid wrapping properties if you can, especially when it causes a need for synchronization.
public ProgramBendingViewModel? CurrentProgramBending => ListingProgramBendingViewModel.CurrentProgramBending;
this is what you call wrapping right ?Delete
public ProgramBendingViewModel? CurrentProgramBending => ListingProgramBendingViewModel.CurrentProgramBending;
and instead use subproperties binding syntax.
Yes, you want to avoid that.how do i do that
"{Binding ListingProgramBendingViewModel.CurrentProgramBending.SomeProperty}"
Assuming the current DataContext
is an instance of ProgramBendingSelectViewModel
.ohhh i can do that ok i though i needed to rewrite my property in my viewmodel to access it in xaml
what is the opc event that pobiega mentionned ?
Your usage of
OnPropertyChanged
. It needs to be raised from the object instance that contains the property.
Which is one reason why forwarding / sync'g across object instances is quite awkward.
You'd likely need to subscribe to INPC, check for changes, and then raise INPC again on the wrapping VM.
(There are a few other ways via concepts like reactive properties, but that's far outside of the scope and still a pain.)ok i will keep your first solution
i've tried this and it seems to work in first i thought i needed to wrapp my property in order to use it in my viewmodel
You really only do wrapping in the case where you have a domain model or such that you can't bind to. Because: 1. it doesn't support binding and 2. if it could, that breaks MVVM.
So you either wrap, manually sync (in commands or such), or do full mapping...depending on how you work with your domain.
ok there is so much thing i still need to learn 😅
thanks for the responses :3
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.