Search code examples
wpfunity-containerprism

How to access control in viewmodel


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.


Solution

  • 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;
    }