I need to know the window handle from the presentation model

I know its anti-pattern to have specific WPF connections to presentation models. But in this case, I can’t avoid it (I use SLIM DX to enter the joystick and require a pen).

So, is there a way from the presenation model to get a handle to the window associated with the model?

thank

+3
source share
2 answers

If I understand that if your view model is inherited from the screen, you can call GetView, apply it to the type of your view and access the control in the view.

var myView = GetView() as OrderView;
myView.SlimDX ...

An alternative, if you do not want to refer to your view from a virtual machine, you could do what you need in the coroutine.

" . " " " ", , . Action, ActionExecutionContext, IResult, UI. ViewModel - , , ActionResultContext:"

public class ActionExecutionContext
{
    public ActionMessage Message;
    public FrameworkElement Source;
    public object EventArgs;
    public object Target;
    public DependencyObject View;
    public MethodInfo Method;
    public Func<bool> CanExecute;
    public object this[string key];
}

http://caliburnmicro.codeplex.com/wikipage?title=IResult%20and%20Coroutines&referringTitle=Documentation

+1

, , ​​ , OnViewLoaded , , .

0

All Articles