0

I tried to used a Message Box Ressult to tried to navigate to other, or the same WPF Page when the MessageBox.Result was Cancel button, but I don't know if it´s possible. I tried to do something but not function (The comment line from MessageBoxResult.Cancel)

class RegistroFullBLL
    {
        ........
   foreach (object item in e.OldItems)
            {
                RegistroFullBO obj = item as RegistroFullBO;
                //********* Caja de Confirmación de Mensaje**********
                var msg1 = MessageBox.Show(" ¿ Desea borrar el Registro ?", "Confirmación de Solicitud", MessageBoxButton.OKCancel,
                        MessageBoxImage.Question);
                if (msg1 == System.Windows.MessageBoxResult.OK)
                {
                    //******** Se llama al método para borrar el Registro de la Base de Datos *********
                    BorrarFilaRegistro(obj.Registro);
                    MessageBox.Show(" Se borró el registro con éxito", "Solicitud Confirmada", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else if (msg1 == System.Windows.MessageBoxResult.Cancel)
                {
                    //this.NavigationService.Navigate(new PagRegistro());                      
                }
    }
  • using "NavigationService" requires your application to be set up with Frames and Pages: http://msdn.microsoft.com/en-us/library/system.windows.controls.frame.aspx – McGarnagle May 12 '14 at 17:22
  • I guess that Navigate is not what you're looking for (since it seems like you're not familiar with its usage). Instead, you probably want to swap out your main window's content for a new instance of "PagRegistro". – McGarnagle May 12 '14 at 17:23
  • that happen is, this class is the logic layer from de page I want to reload. I tried "//this.NavigationService.Navigate(new PagRegistro()); " in the code behind from the page and it function well, but I just wanna know if it's possible from other class – Alvaro Mancera May 12 '14 at 18:09
  • Ah! Sorry, my mistake. I'll post an answer in a second... – McGarnagle May 12 '14 at 18:16

1 Answers1

0

You can't access "NavigationService" from a class or service library, so you will need an alternate method. I see two possibilities:

One option: return a value from your logic library:

public bool SomeMethod()
{
   // ...

   else if (msg1 == System.Windows.MessageBoxResult.Cancel)
   {
       return false;
   }
   return true;
}

That way, you can perform the navigation, or not, in the application:

void SomeMethodInTheApp(RegistroFullBLL registroFullBLL)
{
    if (!registroFullBLL.SomeMethod())
    {
        this.NavigationService.Navigate(new PagRegistro());
    }
}

Another option: pass in a delegate from your app to the logic layer. Eg:

public void SomeMethod(Action onCancel)
{
   // ...

   else if (msg1 == System.Windows.MessageBoxResult.Cancel)
   {
       onCancel();
   }
}

Then from your application:

void SomeMethodInTheApp(RegistroFullBLL registroFullBLL)
{
    registroFullBLL.SomeMethod(() => this.NavigationService.Navigate(new PagRegistro()));
}
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
  • Yes, I used the first option you have suggested, but an error born: – Alvaro Mancera May 13 '14 at 22:06
  • Yes, I used the first option you have suggested, but an error born: "NullReferenceException not found-Object reference not set to an instance of an object." and the second one, I can´t use it, 'cause the method is inside an Event. – Alvaro Mancera May 13 '14 at 22:11