9

I'm using Microsoft.Win32.OpenFileDialog in my WPF application for selecting file:

var dlg = new Microsoft.Win32.OpenFileDialog
{
    Title = "Select configuration",
    DefaultExt = ".xml",
    Filter = "XML-file (.xml)|*.xml",
    CheckFileExists = true
};

if (dlg.ShowDialog() == true)
{
//...
}

According to MSDN screenshots on Windows 7 dialog must have modern style, but I'm getting the old one:

enter image description here

Adding manifest like in this question doesn't works. How to get dialogs like in MSDN shown?

EDIT:

First of all, I'm interested in "native" solution, not using third-party components.

Community
  • 1
  • 1
kyrylomyr
  • 12,192
  • 8
  • 52
  • 79
  • I know the comment "works on my machine" isn't usually helpful, but I pasted your code into a newly created project on my Windows 7 box. The correct dialog is displayed. Is there anything unusual about your machine settings? – Cameron Peters Mar 26 '11 at 14:10
  • @Cameron Peters, Windows 7 x64. WPF project for .Net Framework 3.5. What application have you created (for .Net 3.5 or 4.0)? – kyrylomyr Mar 26 '11 at 14:20
  • Windows 7 Ultimate, 32 bit. WPF project for .Net Framework 4.0. – Cameron Peters Mar 26 '11 at 16:05
  • 3
    when I switch the target to .Net 3.5, I get the old style dialog. Are you able to target 4.0, or are you required to stick with 3.5? – Cameron Peters Mar 26 '11 at 16:15
  • @Cameron Peters, I can switch. Probably with .NET 4.0 `OpenFileDialog` executes new code with modern dialogs. Thanks for helping. Add this to your answer, I will mark it. – kyrylomyr Mar 26 '11 at 16:24

1 Answers1

5

You will get the correct dialog if you switch your target to the .Net 4.0 full or client profile.

Some of the modern common dialogs are only available in WPF if you use the Windows 7 Code Pack, but the new style open dialog is available when you target .Net 4.0.

Cameron Peters
  • 2,502
  • 2
  • 27
  • 34
  • its a possible way, but how Microsoft got modern dialogs with their code snippet in MSDN? Or its a fake? By the way, most of features of Windows 7 Code Pack was added in .Net Framework 4. – kyrylomyr Mar 25 '11 at 20:33
  • @archer. I'm guessing now, but try adding a manifest to your application. Perhaps that impacts the choice of which set of common dialogs to use... sorry couldn't find a good link on the topic in the 10 seconds I have to respond before heading home for the weekend... – Cameron Peters Mar 25 '11 at 22:19