문제

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.

도움이 되었습니까?

해결책 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;
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top