C # / WPF: Open File Dialog Box

I am new to WPF and am trying to create my first WPF desktop application using VC # Express.

I am trying to make three open dialogs with full text boxes that show the specified path if the user selects a file. I found working code to make the dialog appear with a single click of a button, but how do I get the textbox to update / bind to the file path?

Something similar to how file input fields are ideally suited to HTML work.

...

EDIT:

Ok, I read the post just below mine and found a solution ...

Now, what about redirecting the console output to a textbox?

0


a source to share


2 answers


To answer the question about redirecting console output:

You'd be better off changing your code to fire the event with the line you want to output. Then, in the UI, add a handler for this event, and in the handler, update the text box.

To declare an event, add something like this to your handling class:

public event EventHandler<StringEventArgs> Process_Message;

      

where StringEventArgs

is the class based on EventArgs

that wraps the message to send.

To fire an event, add something like this code to your handling class:

Process_Message(this, new StringEventArgs(message));

      

To add a message handler to your UI class:



process.Process_Message += Process_Message;

      

To handle the event, add something like this code to your UI class:

private void Process_Message(object sender, StringEventArgs e)
{
     Action action = () => UpdateStatus(e.Message);
     {
         Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, action);
     }
     else
     {
            action();
     }         
}

      

You need to do a thread check as the UI cannot be updated from another thread.

Then the method UpdateStatus

:

private void UpdateStatus(string message)
{
    statusTextBox.Text = message;
}

      

Obviously, you need to rename whatever suits your application.

Search for events and EventArgs

on MSDN.

+1


a source


If I understand you correctly Use FileDialog.FileName for the full path .. and bind it to the text field. 76mel



0


a source







All Articles