Open Andrej123456789 opened 2 years ago
But we can use the WinForms's MessageBox in WPF.
@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.
WPF should be using TaskDialog not MessageBox. Every supported version of Windows has this API now.
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.
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).
I will try it soon
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 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.
Here is screenshot of error
Nevermind, now works
But point of this issue to use TaskDialog as default
@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.
Oh
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.
@aquinn39 By default, we will reference the System.Windows.Forms in dotnet core.
@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."
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
@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, @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."
- Does this refer to the rounded corners ( as in Windows 11 theme ) ??
- 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.
There are already rounded corners so my focus is on buttons
You can use the Task Dialog for more modern Message Boxes:
FYI TaskDialog requires comctl v6
@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.
Do you have planes for changing default manifest to use modern controls
MessageBox is design is kind of Windows 9.x era. Please add better design at MessageBox.
Example - WPF:
Example - WinForms:
WinForms's MessageBox is much better.