S
S
Sergey2022-02-06 19:37:40
WPF
Sergey, 2022-02-06 19:37:40

How to handle dependency property change event?

I am creating some custom element - block which has inputs and outputs. I have already worked with dependency properties and bindings (in combination with converters, but without validation and fixing yet), and I think that it is logical to set the number of inputs and outputs with the corresponding properties. (or maybe one, but taking a special structure, but not the essence).

Before, I solved the problem of calculating the width and height of a block, based on the logical width, height and scale, using binding (to several properties) and using a converter that had all the logic. (In fact, just multiplying boolean values ​​by the scale)

Another thing is that when you set the number of inputs or outputs, previous inputs or outputs will be created and removed. But it’s quite difficult to implement this in converters, since they are in a separate class and therefore cannot so easily affect the user element, and it doesn’t sound logical, because we are not converting anything here, and the result of the conversion will most likely be just the number that was received initially .

Alternatively, you can create a method of type: SetInputCount , but I think this is not the best solution, even if it definitely works.

On the msdn site, I read that yes, you can bind to property changes, but alas, I could not figure it out. Can you give some rudimentary example of how to handle dependency property change event?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question