I am working in a WPF project, I am using MVVM patter in my project.
I created a user control (also in WPF) and I want to use it in my project, now the problem is that I have a method in my user control that I need to call from my view model, but I donβt I know how to do this, how to bind to a method inside my control from a view model.
If I use the code behind, it is obvious that there is no problem, as I have a direct link to my control, so I can do "mycontrol.MyMethod ();" m, but of course this will go against the logic of the MVVM pattern.
I tried to use the Dependency property in my user control and use the Dependency property to bind to it in the xaml of my project, but it did not work, the compiler says that the property was not found or is not serializable.
So, I would be grateful if someone could tell a little about how I can do this.
Edited
As far as I understand, you have a view that represents the entire graphical interface, then you have a model that is all the logic, and you have a view model that looks like an intermediate layer used to bind the view to the model, right?
Thus, I developed my project, however, I came to the problem that I need a custom control, a text block that remembers what the user entered, and when it starts typing, if there are words starting with this letter, these words are shown as an offer like Google does.
This TextBox is used as a search filter; so I created a user control for this, I added a method for my user control so that any application using my control would add elements to the internal array that contains all the rows that the user entered.
I created a user control because I could not find any control that behaves the way I want.
So, my problem is when I add my user control to the main project, because I need to somehow call a method that adds the elements to the internal array, but maybe I'm doing something wrong if one of you has a better idea, I would be grateful if you shared it with me.