Domanda

My app is in WPF,VS 2010 PRISM and Unity. i want to access Views Dockpanel control in viewmodel when constructor initialization for Adorner. any help would be appreciated.

È stato utile?

Soluzione 2

Simple way is that you can resolve IUnityContainer of View and can access control like:

readonly IUnityContainer _container;

public CONSTRUCTOR(IUnityContainer container)
{
    _container=container;
    var resolved = _container.Resolve<IEmployeeView>();

    // cast your resolved view as View.
    var views = resolved as YOURVIEWNAME;

    // and get control.
    var controls = views.YOURDOCPANELNAME;
}

Altri suggerimenti

Yup. The correct response is you DON'T. In MVVM, the VM should have no knowledge of Views at all. You should be binding the View to the View Model.

However, there are of course certain cases where this pattern/model breaks down. At this point you can consider using the MVPVM pattern *. The class that MAY access the View is called the Presenter.

*Seriously, I'm not even kidding on this one. This link is a Microsoft magazine link.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top