1

From what I read System.Windows.MessageBox is available in .net core 5 links:

https://learn.microsoft.com/en-us/dotnet/api/system.windows.messagebox?view=net-5.0

Similar method to messageBox in .NET core

However when I try to use System.Windows.MessageBox I get the error: The type or namespace name 'MessageBox' does not exist in the namespace 'System.Windows'

Am I missing a setting?

Paul McCarthy
  • 818
  • 9
  • 24

1 Answers1

2

Assuming you want to use WPF, your csproj file has to look like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF> <!-- this adds support for the GUI stuff like MessageBox -->
  </PropertyGroup>
</Project>

Then you should be able to do something like this in MainWindow.xaml.cs:

using System.Windows;

namespace messagebox
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
            MessageBox.Show("Hello World!");
        }
    }
}
mu88
  • 4,156
  • 1
  • 23
  • 47