How to subscribe events in nested ChildRegion #2506
Unanswered
ngoquoctoandev
asked this question in
WPF
Replies: 1 comment 2 replies
-
First off, don't use Shared projects with EventAggregator. Shared projects are compiled into the referenced project and seen as a separate class. Meaning your messages will not work because the Event class will not be seen as the same event class across your various projects. You also can't send message to objects that don't exist, and you can't add views to a region until it exists. You'll have to make sure you understand the lifecycle of your application to implement this in your app. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a form designed like this:
MainWindow contains a TextBlock and a ContentRegion.
I registered ViewA to ContentRegion when MainWindow is initialized.
On ViewA I designed two buttons to call ViewB, or ViewC into ChildRegion of ViewA.
I publish an event at the OnStartup method to send a message to all ViewModels that subscribe to it.
Scenario 1: ViewA receives the event while ViewB, ViewC do not receive this event. But it can only call ViewB, ViewC into ChildRegion of ViewA. Obviously now in RegionManager only contains ContentRegion, does not contain ChildRegion, so the event registered at ViewB, ViewC will not receive.
Here is the code I wrote:
And this is how I call ViewB, ViewC into ViewA's ChildRegion
Scenario 2: I assign object of IRegion to constructor of ViewAViewModel, but error occurs because RegionManager does not contain ChildRegion.
Is there any solution to register ChildRegion on initialization to receive events at ViewB, ViewC as soon as program is showed?
This is my source code, can anyone help me to receive events at ViewB, ViewC as soon as the program appears?
https://github.com/z2hteam/PrismWpfDemo.git
Beta Was this translation helpful? Give feedback.
All reactions