4

Can anyone please help me? I want to use WndProc in WPF but I don´t want to use it in the MainWindow.xaml.cs like this:

    public MainWindow()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        base.OnSourceInitialized(e);
        HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
        source.AddHook(WndProc);
        _windowHandle = source.Handle.ToInt32();
    }

I want to use it in a different class the reason is that the uEye camera communicates over messages and I need to "catch" them. And because I am using the Main View ViewModel Model I dont want to enter code to the MainWindow.xaml.cs.

Basde
  • 43
  • 3

1 Answers1

4

MVVM do not say that you cannot write code in the View layer. It say that you have to write code to access Model in ViewModel and try to keep the connection between View and ViewModel as easy as possible (normally with a binding).

In this case you are writing in the view layer code to access to the WndProc that is part of View layer.

So in my opinion your code is perfectly MVVM compliant.

Roberto
  • 504
  • 11
  • 23
  • 1
    As Roberto said, adding on that, you might want to move any business logic that the WndProc will be directing to or performing after capturing the windows message, to your ViewModel class – Tarek Khalil Apr 26 '12 at 11:19