문제

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());                      
                }
    }
도움이 되었습니까?

해결책

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()));
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top