1

How can i move

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) 

to the viewmodel and still be able to control "back'ing"? In the codebehind, i can use e.Cancel = true;, but how to use it in the viewmodel?

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64

2 Answers2

0

The very first idea that i got - is to leave it in codebehind, and send message to viewmodel, so it should shange its state. But i'd still prefer to bind event to VM.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64
0

You can't bind something that isn't bindable per say. All you can do is either create a fake binding using a Behavior<T>, but not much point in that.

Instead you could just simply forward the event in the ViewModel, doing something like:

e.OnCancel = ViewModel.OnBackKeyPress();

And then have OnBackKeyPress() return a bool.

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
  • But looking like messaging is exactly the thing, which was designed to prevent having access from view to viewmodel :) Right now i'm looking at messaging documentation... i guess, i saw a callback somewhere, so i'd be able to return bool with message. – Vitalii Vasylenko May 02 '13 at 11:08
  • 1
    Except messaging is async, and OnBackKeyPress is synchronous. – Claus Jørgensen May 02 '13 at 11:33