consolecontrol
consolecontrol copied to clipboard
WPF console app does not work
Great project! The WinForms version works fine, but the WPF version does not work (at least on Windows Server, which is where I am running it on). I am unable to type characters into the window / no input is accepted after starting the console connection.
Thoughts?
WinForms is working perfectly fine but WPF version is not interacting with the shell. On giving any input, there is no output. Can you help?
It gives the sensation that this project is abandoned. in wpf you can not make any entry by keyboard. nor dir. nor launch any command. If someone has solved it, I would appreciate the solution. Thank you
I was looking for ideas how to "make" a WPF console for my project and ended up here - actually I do like the work Dave did, it's nice piece of code with good ideas behind. However I have had issues to make the WPF park working, so I have quite redesigned some parts to make it work. If still somebody interesting in the WPF part, you can check the code within the project I use the console in. The important files for console WPF control are in Console XAML part ProcessWrapper (ProcessInterface here) RichTextBox extensions used
I will take a quick look when I get back home @adamecr! For some reasons I had notifications disabled for this project so I've not been keeping up to date with it. If I can get it working based on your input, are you OK for me to update the code in this repo then credit you as a contributor?
Hello Dave @dwmkerr , I have found some issue with BackgroundWorker, I have a fix, but just finishing the release of other functionality of my VSIX, so I think, I'll upload the latest code during the weekend (I use the GitHub just as a public mirror of my release branches). Once it's done, I'll get back with more details what I have done to make the console working, so it will make the digging through the code easier. Of course no problem with using my findings/code here.
So I'm back to summarize the updates I have made to make the control working in WPF. The key part was in ConsoleControl.xaml.cs:
- RichTextbox's
PreviewKeyDown
event is to be used instead ofKeyDown
due to bubbling nature of WPF event routing. - I use the immutable
inputStartPos
to identify the end of read only zone. When it's assigned from Selection.Start, it just gets the reference and changes over the time. So I "measure" the position as integer ordinal from content start.
I think these two changes are crucial and the rest are just the improvements and/or adjustments:
-
StartProcess
supports optional working directory definition (like request in issue #18) - I added the command history (Ctrl-Up, Ctrl-Down) to the console control.
-
Esc
clears the current input. - I added the brushes for input, output, error and diagnostics as dependency properties of control, so they can be customized when using the control in XAML.
- I handle
IsInputEnabled
in key handler rather then (re)setting the read only property on process start, so it can be changed dynamically when needed. - Console scrolls to the end when output is added. But be careful - this might be slow when there is a lot of content in the console (WPF version of issue #1).
- I added handler disabling the selection drag-and-drop to protect the read only area.
- I merged output and error processing/handler from backing process (see later). This is just simplification for me.
The updates to ProcessInterface (I call it ProcessWrapper) are not really game changers:
- The
StartProcess
supports optional working directory definition. - The
StartProcess
doesn't start a new process when there is a process already running. - I don't split the output and error events as I do handle them the same way in control, so I rather use the
IsError
field in event data to signal type of the output. - I wanted to have the ability to restart (or start another) process in the process-exited handler, but this got me into the problems with asynchronous cancellation of the BackgroundWorkers processing the standard and error output - they have not been finished (cancelled) before the new process starts and I didn't want just to create a new instances of workers. So I have implemented
BackgroundWorkerWithSyncCancel
giving me better control over the workers. Not sure, but it might also help with issue #20
That's it, hope this helps... Should you have any questions, just raise the comment.
If you want to have a look into my version of code or use the console control itself, you need these files: ConsoleControl.xaml ConsoleControl.xaml.cs RichTextBoxExtensions.cs ProcessWrapper.cs BackgroundWorkerWithSyncCancel.cs
@danielseis found a solution, posted the fix in i a new Issue.. i know it has been a while since 2018.. Best regards