Disable WinFormsAvaloniaControlHost in design mode #16296
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
This pull request disables the creation of an
EmbeddableControlRoot
inWinFormsAvaloniaControlHost
when it is in design mode, i.e. run by the Windows Forms designer.Furthermore, I added a rectangle with a caption Avalonia control is disabled in design mode. which is rendered in design mode only to inform help developers find their control in the designer and give them a hint why they cannot see their Avalonia control.
What is the current behavior?
When you add a
WinFormsAvaloniaControlHost
to your Form, the control throws an exception.First, you will be shown this message box by Visual Studio every time you open the designer which is very annoying.
Secondly, in place of your control host the designer will render a big error message which is hard to ignore while using the designer for other controls.
What is the updated/expected behavior with this PR?
Now, the control does not throw an exception anymore and the designer instead shows a subtle hint that the Avalonia control is disabled.
How was the solution implemented (if it's not obvious)?
Just two simple if conditions. If
WinFormsAvaloniaControlHost
should become more complex in the future it might make sense to split the runtime and the designer implementation into two different classes.Checklist
Fixed issues
Fixes #16288