The question is theoretical. Imagine that we have a certain window. In the window there are several layers made on the basis of UserControl . Layers are located one above the other, and completely overlap. Each layer has its own views. A view has its own logic for displaying and interacting with the user. That is, input event handling is in view. This is logical, because they know how to display the information correctly.

Attention, question: in case of bubble and tunnel propagation of events, only the most "closest" layer will work, everything under it will not receive input events. And it is necessary to get.

For example, we click into a certain point, and the views of all the layers that the point belongs to react to the click.

I understand that you need to implement some input event dispatcher. But maybe I don’t know something, and there is some standard way to solve this problem.

  • Thanks for correcting. I unfortunately did not find the button to edit ... - Peter

2 answers 2

If I understand correctly, EventArgs has a Handled property. You can set it to false , and the event will go on.

You can also use Messenger to transfer events from one viewModel to another.

Update

In short, there are two methods of Messenger.Register<TMessage> and Messenger.Send<TMessage> . Roughly speaking, each event creates its own TMessage implementation, for example, NewMessage . Any ViewModel can subscribe to events of this type via Messenger.Register<NewMessage> and can also fire this event using the Messenger.Send<NewMessage> method.

  • Alas, Handled will not work, because only works in the context of standard event routing. And you can detail about Messenger? - Peter
  • those. it turns out that it is necessary to make a wrapper from user events for input events. option, but too complicated. It is easier to write a certain router for standard input events. - Peter

It is not entirely clear why the invisible layer should receive events. Once it is invisible, the user does not assume that there is something that has logic.

If you, on the contrary, have the upper layer partially transparent, and the controls of the lower layer are visible, set it to a null background, and through the transparent areas click and other events will pass to the lower layer.

  • here the matter is that the layers are different and have views of different mechanisms in different coordinate grids. this is dictated by the subject area. including translucent elements. if you remove the background, then the event will take place on another layer, yes. but then the first layer will not work. - Peter
  • @Peter: Well, do you need several elements to react to each click? Tell us a little more about your task. - VladD 4:05
  • Yes something like that. There are different panels on top of each other. and grids and canvases. Views on them are interpositioned according to the principles of the subject area. There are translucent views. there is not transparent. views can consist of almost anything, and have almost any shape. So we put the mouse on some point, an event should be received by all views, on all layers, under this point. it turns out not a hierarchical distribution of events, as in WPF, but a parallel one. - Peter
  • @Peter: Okay, I get it :) Now I’ll try to write something for you. - VladD
  • Well, thanks of course, but the question is a little different. the question is whether there are standard C # or WPF tools for implementing such event routing. Write your dispatcher is not difficult, but will not it be a bicycle. - Peter