简体   繁体   中英

How to call a viewmodel method from another class

In my WPF codes, there's a Reset_btn_click() method in MainWindows.xaml.cs file (which will deal with a lot of actions with UI, that's why i don' t want to move this method to another file). since the program will reset itself several times in a single run, and I'd like to reuse this function instead of writing new one in control class. so how do i call this method from another class

Thanks

public class Example
{
    public void Method1(MainWindows mainWindows)
    {
        mainWindows.Reset_btn_click();
    }
}

In MainWindows.xaml.cs object creation is like this

 Example Ex = new Example();
 Ex.Method1(this);

Hope this helps but I'm a bit confused if you are using mvvm as your saying ViewModel there won't be any code in MainWindows.xaml.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM