dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.06k stars 1.17k forks source link

Better MessageBox #5967

Open Andrej123456789 opened 2 years ago

Andrej123456789 commented 2 years ago

MessageBox is design is kind of Windows 9.x era. Please add better design at MessageBox.

Example - WPF: image

Example - WinForms: image

WinForms's MessageBox is much better.

lindexi commented 2 years ago

But we can use the WinForms's MessageBox in WPF.

ThomasGoulet73 commented 2 years ago

@Andrej123456789 MessageBox is just a wrapper around the Win32 control. WPF does not control the styling inside the MessageBox. You need an app mainfest to use the more modern controls.

Content of app.manifest:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

WinForms seems to work without the need for an app manifest (My guess is that it comes from this line: https://github.com/dotnet/winforms/blob/main/src/System.Windows.Forms/src/System/Windows/Forms/MessageBox.cs#L388). It would be interesting to try to add in WPF the code from WinForms that fixes this.

ClosetBugSlayer commented 2 years ago

WPF should be using TaskDialog not MessageBox. Every supported version of Windows has this API now.

psmulovics commented 2 years ago

https://docs.microsoft.com/en-us/windows/win32/controls/task-dialogs

RussKie commented 2 years ago

Windows Forms SDK provides an app.manifest by default, so the comctl 6.0 is used by default as well (with the ubiquitous Appplication.UseVisualStyles() call in Program.cs). I don't know if WPF provides a default manifest, so this is something to check.

RussKie commented 2 years ago

WPF should be using TaskDialog not MessageBox. Every supported version of Windows has this API now.

It isn't straightforward to correctly use Win32 API, and it requires a lot of elbow grease without managed wrapper (e.g., https://github.com/dotnet/winforms/pull/1133).

Andrej123456789 commented 2 years ago

I will try it soon

ClosetBugSlayer commented 2 years ago

It isn't straightforward to correctly use Win32 API, and it requires a lot of elbow grease without managed wrapper (e.g., dotnet/winforms#1133).

The only elbow grease is if you use an activation context, which I do personally just to be safe. Otherwise the default manifest should pull in the API as-is; it works for me in .NET 6 at least.

Andrej123456789 commented 2 years ago

@Andrej123456789 MessageBox is just a wrapper around the Win32 control. WPF does not control the styling inside the MessageBox. You need an app mainfest to use the more modern controls.

Content of app.manifest:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

WinForms seems to work without the need for an app manifest (My guess is that it comes from this line: https://github.com/dotnet/winforms/blob/main/src/System.Windows.Forms/src/System/Windows/Forms/MessageBox.cs#L388). It would be interesting to try to add in WPF the code from WinForms that fixes this.

I tried this but I can't compile project anymore. Here is file so you can check it out.

image Here is screenshot of error

Andrej123456789 commented 2 years ago

Nevermind, now works

Andrej123456789 commented 2 years ago

But point of this issue to use TaskDialog as default

miloush commented 2 years ago

@Andrej123456789 no the original issue is asking for WinForms matching message box, and that is solved using manifest. If you have a TaskDialog API request, upvote #2902.

Andrej123456789 commented 2 years ago

Oh

aquinn39 commented 2 years ago

Another way to solve this if you can't/don't want to use the app manifest is to call System.Windows.Forms.Application.EnableVisualStyles() when the app starts. Similar to the manifest solution, this enables visual styles for Forms and GDI controls, such as the message box. <UseWindowsForms>true</UseWindowsForms> must be set in the project file for .Net apps to do this and for .Net Framework apps, a reference to System.Windows.Forms needs to be added to the project.

lindexi commented 2 years ago

@aquinn39 By default, we will reference the System.Windows.Forms in dotnet core.

dipeshmsft commented 2 years ago

@Andrej123456789, @miloush got a bit confused about what are we talking about in this issue.

TaskDialog request is a different issue, I am clear on that.

Now, going through the first comment in this thread, it's mentioned that "Please add better design at MessageBox."

  1. Does this refer to the rounded corners ( as in Windows 11 theme ) ??
  2. Or are we referring to the icon and buttons in the message box control ??

Because we have other public Show functions which can be used to display those. https://github.com/dotnet/wpf/blob/a71d94d93b4af94061f6cd27c57b1d00efaccaab/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MessageBox.cs#L95-L146

miloush commented 2 years ago

@dipeshmsft I agree that the original post does not actually mention what the perceived issue is. From the screenshot, my interpretation was the button styling, which can be solved by manifest. Good call pointing out that the user can add an icon and a title with different overload.

Andrej123456789 commented 2 years ago

@Andrej123456789, @miloush got a bit confused about what are we talking about in this issue.

TaskDialog request is a different issue, I am clear on that.

Now, going through the first comment in this thread, it's mentioned that "Please add better design at MessageBox."

  1. Does this refer to the rounded corners ( as in Windows 11 theme ) ??
  2. Or are we referring to the icon and buttons in the message box control ??

Because we have other public Show functions which can be used to display those.

https://github.com/dotnet/wpf/blob/a71d94d93b4af94061f6cd27c57b1d00efaccaab/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MessageBox.cs#L95-L146

There are already rounded corners so my focus is on buttons

victorgoebel commented 1 year ago

You can use the Task Dialog for more modern Message Boxes:

image

image

RussKie commented 1 year ago

FYI TaskDialog requires comctl v6

miloush commented 1 year ago

@RussKie which ships with Vista so it should be fine. With CreateActCtx you don't even need a manifest, though I am wondering why that is not part of the default embedded manifest nowadays.

EDIT: CreateActCtx does require a manifest, it just doesn't need it to be embedded in the application.

Andrej123456789 commented 1 year ago

Do you have planes for changing default manifest to use modern controls