4

私はWPFアプリでSystem.Windows.MessageBoxを使用していますが、何らかの理由で、そのボタンのスタイルはWindows 2000のようになっています。WinXP、Aero、WPFのデフォルトではありません。基本的な3Dボーダーでちょうど灰色。

どうすればよりモダンなスタイルでそれらを表示させることができますか?(どちらでもかまいません)

4

1 に答える 1

7

これはマニフェストで修正できます。ステップバイステップの手順については、この記事を参照してください:WPFで古いスタイルのファイルダイアログとメッセージボックスを取得するのはなぜですか

基本的に、「マニフェスト」と呼ばれるXMLファイルをアプリケーションに追加する必要があります。

アップデート:

実際、VS2008ではこれを行うのは非常に簡単です。[プロジェクトのプロパティ]->[アプリケーション]に移動し、[UAC設定の表示]ボタンをクリックします。これにより、アプリケーションマニフェストファイルが自動的に作成されて開きます。このファイルを次のように編集します。

行の直後:

</trustInfo>

次の依存関係セクションに貼り付けます。

  <!-- Activate Windows Common Controls v6 usage (XP and Vista): -->
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>

私の完全なマニフェストは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <!-- Activate Windows Common Controls v6 usage (XP, Vista, Win 7) to support themed dialogs: -->
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>
</asmv1:assembly>

これを行った後、アプリをビルドして実行し、出来上がり、MessageBoxダイアログボタンはシステムテーマスタイルになります。

于 2010-01-08T18:51:53.837 に答える