0

I work on a school project in WPF C# and I run into this problem. I use MVVM model for it. Because I'm a beginner in WPF and I have a strick date give this to the teacher I had to use youtube tutorials and internet forums such as this one.

My problem basicly is that I want to use one of my RelayCommand to change the current view, but not in the mainwindow, instead in one of my views. But when I wrote down the code it refuses to realise it as a RelayCommand, but it realise it as a PropertyPath. I Give the examples down below in pictures.

I tried place "invisibly" buttons to the mainWindow and fire them when i click the button that "should change" the view to another, but I can't refer to it from the view's C#. I tried to add them as datacontext with "Ctrl+." solution too, and I got a little success and it recognized it as what is it (AKA RelayCommand), but the function still didn't work.

Basicly that's what I did so far, and I asked the teacher, my classmates and every possible people but nobody had a clue why it doesn't work. Sorry if it's an obvious question, but as I mentioned I'm a beginner and because of the deadline I can't start over again, because I don't have the time for it :( Thank you for reading this "shout" for help, and THANKS in advance if you can help me :)

Have a nice day!

The original command in the MainWindow The command in the other View

  • 1
    Please add your code as formatted code rather than an image of code. Highlight your code using the mouse, and then click `{}`. – Tu deschizi eu inchid Dec 08 '21 at 18:41
  • The problem will be originating from the fact that your MainWindow has another ViewModel databound to it than the ViewModel databound to the OtherView. Depending on the size of your project, you could do a small fix by wiring the ViewModels to each other by adding a property `ParentViewModel` to the ViewModel of the Other View. If you than construct your OtherViewModel in the MainWindowViewModel, you can add `this` as a parameter. If your project is bigger, you can work with the Navigator Design Pattern. As user9938 mentioned, adding more code here will help you solve the problem. – JoachimAlly Dec 08 '21 at 21:33
  • Visit this link for more details. https://stackoverflow.com/questions/22285866/why-relaycommand – Sandeep Jadhav Dec 09 '21 at 15:10

0 Answers0