How do I replace windows form Dialogresul in wpf?

Asked

Viewed 38 times

1

I have that code:

DialogResult dr = ofd1.ShowDialog();

Moving to WPF does not work. I searched the internet and found nothing yet, that satisfy me. As I replace in WPF?

Note: ofd1 is a OpenDialog

3 answers

0

Use the MessageResult

MessageBoxResult result = MessageBox.Show("Questão", "Título", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
    // Fazer algo
}
  • This example I’ve seen on the internet and I couldn’t make it work for it.

  • Didn’t get what? It gets hard to help without knowing what the problem is

  • That doesn’t work: MessageBoxResult dr = ofd1.ShowDialog();

  • You added the namespace System.Windows?

  • The above code I posted comes from an Opendialog and that line I select the file I want to upload. With this example, I can’t open. That’s the problem I’m having. Yes I added the line. No error. It just doesn’t work as expected by this question.

0

That’s how it worked:

Nullable<bool> result = ofd1.ShowDialog();

            if(result == true)
            {
                try
                {
                    LocalizacaoZip = ofd1.FileName;
                    nome_arquivo_zip = System.IO.Path.GetFileNameWithoutExtension(ofd1.FileName);
                }
                catch (SecurityException ex)
                {

                }
                catch(Exception ex)
                { }
            }

0

How do you compare the Openfiledialog result? The code below works perfectly for me..

using System;
using System.Windows.Forms;
    namespace TesteWpf {
        class Program {
            [STAThread]
            static void Main(string[] args) {

                using (OpenFileDialog ofd = new OpenFileDialog()) {
                    if (ofd.ShowDialog() == DialogResult.OK) {    
                    }
                }    
            }
        }
    }
  • For me it works on windows form, but it didn’t work on wpf.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.