Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opacity doesn't work like in WPF #9227

Open
billhenn opened this issue Oct 18, 2022 · 0 comments · Fixed by #9964
Open

Opacity doesn't work like in WPF #9227

billhenn opened this issue Oct 18, 2022 · 0 comments · Fixed by #9964

Comments

@billhenn
Copy link
Contributor

billhenn commented Oct 18, 2022

Describe the bug

I'm coming from a WPF background. I was trying to use a semi-transparent complex element by setting Opacity to < 1. While this worked, the result is not expected since setting Opacity on the root of a complex element seems to make each descendent element get the opacity applied instead of rendering the final result of the complex element at a certain opacity.

See screens below for a very basic example, but keep in mind that in my case, I have a much more complex element that looks awful when all of its parts are showing through each other.

To Reproduce

My test code in both WPF and Avalonia is this where the top half is a fully opaque set of ellipses and the bottom half is the same, but has the containing StackPanel set to 50% opacity:

<Grid Height="200" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Silver">
	<StackPanel Margin="10" Orientation="Horizontal" 
		HorizontalAlignment="Center" VerticalAlignment="Top">
		<Ellipse Margin="0,0,-20,0" Width="80" Height="80" Fill="Green" />
		<Ellipse Margin="-20,0,0,0" Width="80" Height="80" Fill="Blue" />
	</StackPanel>
	<StackPanel Margin="10" Orientation="Horizontal" 
		HorizontalAlignment="Center" VerticalAlignment="Bottom" Opacity="0.5">
		<Ellipse Margin="0,0,-20,0" Width="80" Height="80" Fill="Green" />
		<Ellipse Margin="-20,0,0,0" Width="80" Height="80" Fill="Blue" />
	</StackPanel>
</Grid>

The unexpected result in Avalonia is:
image

You can clearly see how the individual Ellipse shapes are all partially transparent, which is very bad when you have a complex element and set opacity on it.

Expected behavior

The expected result as in WPF is:
image

You can see here the partially transparent StackPanel has its final rendering in tact, but just faded into the background. This is what I would expect in Avalonia too.

Is there any way to achieve this? Otherwise, Opacity is not practical for use.

Even if there is a workaround, I would have expected the WPF-like behavior out of the box.

Desktop (please complete the following information):

  • OS: Windows
  • Version 11.0.0-preview2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants