WPF Control, How to set transparency? #15989
-
I know the work is going on for the WPF and UWP controls, but I was looking on how to set the transparency for the WPF terminal control. Currently, it seems that the theme allows only for a solid background color, so I modified the TerminalSetTheme Method to also do EnableTransparentBackground(true) , however still the terminal control loads using the Background solid color, I looked up the source code for the Terminal app to see how it was doing this, and aside for the EnableTransparentBackground setting (I dont know c++. so I certainly have missed something), I was unable to locate how it did this. That means that I could not find where the transparency setting should be made, does the renderer does this, or will I have to modify something else? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 10 replies
-
How exactly are you running the WPF control? It's not really super well supported, certainly not as a standalone app right now. I'd suspect that even if you set the transparency of the control itself, it would just be transparent to the Background of the app window itself. IIRC it's pretty trivial to change that in WPF: https://stackoverflow.com/a/21461482/1481137 https://github.com/microsoft/terminal/blob/main/src/cascadia/WpfTerminalTestNetCore/MainWindow.xaml |
Beta Was this translation helpful? Give feedback.
-
So I searched the internet and found this, and I was able to make the window transparent by making it layered and then changing its attributes, but there is a weird problem now, if I call this in the CreateTerminalFunction, it works, however from any other function after the terminal has been created such as from TerminalSetTheme, it does not seem to work, here is the code:
and here is the CreateTerminal function in which it works:
And here is the SetTransparency function, I created a new one, from which it does not work (It does not from any other function such as TerminalSetTheme) :
Please don't mind if I am making a noob error here, because cpp is not my language. |
Beta Was this translation helpful? Give feedback.
-
I had another thought here this morning - are we totally sure that the WPF stack is passing colors that have a transparent alpha channel to the renderer? IIRC I can't find that code anymore - we've gone through a bunch of refactors since that was written. But I dunno if WPF ever considered that. |
Beta Was this translation helpful? Give feedback.
-
WPF always passes RGB I think. |
Beta Was this translation helpful? Give feedback.
-
There was no option to pass the Alpha channel. |
Beta Was this translation helpful? Give feedback.
-
A lot of this stuff is going to change with the new converged control platform over in https://github.com/microsoft/terminal/tree/dev/duhowett/win7-wpf-termcontrol. It might be better to check back once that merges! In short: right now the WPF control uses the lower level components of Terminal like the renderer and the VT engine. Because of that, we've had to implement higher-level behaviors like selection and scrolling and color handling (to name a few) two times, and for the most part left the WPF control in stasis. Not intentionally, mind you! Just because it's easy to forget something that isn't built into the core product. In shorter: we're combining the two Terminal controls into one library so they get the same features at the same time. |
Beta Was this translation helpful? Give feedback.
-
Finally, I was able to achieve better looking transparency by incorporating DirectComposition in the renderer code. But that is not available on Windows 7. But at least it will work fine on Win 8 and beyond. |
Beta Was this translation helpful? Give feedback.
Finally, I was able to achieve better looking transparency by incorporating DirectComposition in the renderer code. But that is not available on Windows 7. But at least it will work fine on Win 8 and beyond.