Thursday, January 19, 2012

Using Messanger for calling View method from ViewModel in MVVM structure of Silver light

Write in View Constructor

Messenger.Default.Register(this, "DoFocus", doFocus);

Write method in view that need to be call from view model
public void doFocus(string msg)
        {
            if (msg == "focus")
            {
                System.Windows.Browser.HtmlPage.Plugin.Focus();
                this.txtSalesOrderNo.Focus();
            }
        }

Now you can call the above method from viewmodel as below

Messenger.Default.Send("focus", "DoFocus");

No comments:

Post a Comment