MessageBox Buttons?

前端 未结 6 2064
太阳男子
太阳男子 2020-12-28 14:14

How would I say if the yes button on the messagebox was pressed do this,that and the other? In C#.

6条回答
  •  没有蜡笔的小新
    2020-12-28 14:55

    An updated version of the correct answer for .NET 4.5 would be.

    if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxImage.Question) 
        == MessageBoxResult.Yes)  
    {
    // If yes
    }
    else  
    {
    // If no
    }
    

    Additionally, if you wanted to bind the button to a command in a view model you could use the following. This is compatible with MvvmLite:

    public RelayCommand ShowPopUpCommand
    {
       get
       {
       return _showPopUpCommand ??
          (_showPopUpCommand = new RelayCommand(
             () =>
                   {
                    // Put if statement here
                   }
          }));
       }
    }
    

提交回复
热议问题