A
A
Ark Tarusov2018-09-14 21:04:02
.NET
Ark Tarusov, 2018-09-14 21:04:02

How to make two way Binding vector2 to two textBox?

Hello!
I store the coordinates on the map and pairs of min \ max in variables of the Vector2 type.
There was a necessity to deduce\set a part of the data on the form.
There are two textblocks on the form, it was planned to display \ read the x value of the vector in one, in the second y.
You can’t do it just like that, there is no access to the vector data. A converter was written that can give us the desired parameter from the vector, depending on the specified argument, so it was possible to implement the output of information.
But it was not possible to implement the input in this way, since the converter takes the received value into itself in this case, and does not know about the vector. therefore I cannot apply the received value in a vector.
Now I have made additional properties in the viewmodel, it looks dumb, takes up a lot of space, most likely a terrible crutch. Well, plus, my model with data is selected from the list, when selected, an update occurs, etc., and so on, and the necessary vectors are in this model, and therefore the hemorrhagic comes out with updates ...
Maybe there are some options?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ark Tarusov, 2018-09-15
@kreo_OL

In general, in fact, no way.
One of the best options is to create properties of type vector2x vector2y in the model itself.
Like so

public float MapCoorX
        {
            get => MapCoordinate.X;
            set
            {
                MapCoordinate = new Vector2(value, MapCoordinate.Y);
                OnPropertyChanged();
            }
        }

If there are several vectors, or for example it is an array of vectors, then you can create a SelectVector2 field, then in principle you can choose options.

L
LiptonOlolo, 2018-09-15
@LiptonOlolo

What are the difficulties?
Judging by the office. Documentation field X - public, you can bind as you like: Or show the code with a description of where exactly it does not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question