开发者

WPF MessageBox buttons aren't OS themed

开发者 https://www.devze.com 2023-02-18 09:48 出处:网络
So the buttons of my message box in WPF aren\'t themed by the OS. I even tried this method and it didn\'t work.

So the buttons of my message box in WPF aren't themed by the OS.

I even tried this method and it didn't work.

I have a manifest, I am running under Windows 7 Ultimate x86 and .NET Framework 4 Clien开发者_Go百科t Profile.


EDIT: It works now.


This is an odd glitch in WPF, it is missing the plumbing to activate visual styles. Doubly-odd because this isn't hard to do.

The workaround is modify the manifest that gets embedded in your program. Select your EXE project, then Project + Add New Item, General, select Application Manifest File. You get the default manifest that gets embedded, note the <assemblyIdentity> and <trustInfo> elements. Paste this in between:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

The message box will now have the operating system's visual style, the Aero look with the glowing close button by default on Vista and up.

If you do this in Visual Studio 2010 then this manifest entry is already present but is commented out. You'll find it at the bottom of the file. Just remove the comments, the <!-- before <dependency> and the --> after </dependency>

Beware that this manifest is not enabled when you run with the debugger and the Visual Studio hosting process enabled. That's a different .exe file in your build directory, yourapp.vshost.exe. Project + Properties, Debug tab, scroll down, untick "Enable the Visual Studio hosting process". That has a few side effects related to security, there isn't much point in actually doing this since your user will never have this problem.


The changes you've made have been saved but you cannot view them whilst debugging in VS. To fix this, right click your project and click "Properties" and then go to "Debug". There is a checkbox at the bottom of the page named "Enable the Visual Studio hosting process" - un-tick this. It is recommended that you restart visual studio after making this change.

Alternatively, you can just build without debugging (CTRL+F5).


You could try using http://elegantcode.com/2010/08/05/extended-wpf-toolkit-new-messagebox-control/ - code posted within http://wpftoolkit.codeplex.com/

More documentation also on http://wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Home

0

精彩评论

暂无评论...
验证码 换一张
取 消