question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VisualBrush Clips Image of Control

See original GitHub issue

The bug If I use a VisualBrush to draw a control, which is not positioned on 0/0 (Bounds X/Y), the drawn control is cut off (clipped), although no clipping, transformation,… is applied to the source-control.

The only way I could make it not clipped was to use RenderTransform on the source control, which breaks the original rendering of the control, so this is no valid workaround.

To Reproduce Steps to reproduce the behavior:

  1. Create new Avalonia 11 Preview 5 app called “Project1”
  2. Use this AXAML
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:local="using:Project1"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="Project1.MainWindow"
        Title="Project1"
		Background="#666">
        <StackPanel Orientation="Horizontal">
		<Button Name="a" Width="50">aaa</Button>
		<TextBox Name="text" IsReadOnly="False" Background="#444">
			<!--<TextBox.RenderTransform>
				<TranslateTransform X="-50"/>
			</TextBox.RenderTransform>-->
			asdfdddd
		</TextBox>
		<Button Name="b" Width="100" Background="Orange" ClipToBounds="False">
			bbb
		</Button>
		<Button Width="100">ccc</Button>
		<Rectangle Stroke="Red" StrokeThickness="1" Width="200" Height="100">
			<Rectangle.Fill>
				<VisualBrush AlignmentX="Left" AlignmentY="Top" Stretch="None" 
							 Visual="{ResolveByName text}">
				</VisualBrush>
			</Rectangle.Fill>
			
		</Rectangle>
		<Button Width="100">ddd</Button>
	</StackPanel>
</Window>

  1. See that in the rectangle, the text input control is cut off by exactly the Bounds.X amount
  2. Now uncomment the TextBox.RenderTransform
  3. The TextBox is not cut off anymore in the rectangle

You can try to change the size of the first control and you will see it is always cut off by its width amount.

Investigation The issue seems to come from the initial translation in ImmediateRenderer.Rendermethod: https://github.com/AvaloniaUI/Avalonia/blob/1af62aee84bc750ffc442b86a5d777ac397f05c2/src/Avalonia.Base/Rendering/ImmediateRenderer.cs#L86 and then later applied https://github.com/AvaloniaUI/Avalonia/blob/1af62aee84bc750ffc442b86a5d777ac397f05c2/src/Avalonia.Base/Rendering/ImmediateRenderer.cs#L119

It seems to me this initial value for m is unnecessary/wrong, or at least applied in a wrong way.

Expected behavior If no clipping, translations,… are applied to the input visual of VisualBrush, then the whole control should be drawn/visible and not clipped.

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 11 22H2 Build 22621.1194
  • Version: 11 Preview 5

Additional context I discovered this bug while trying to workaround/fix the TabView control in the FluentAvalonia project https://github.com/amwx/FluentAvalonia (in “New Controls” -> “TabView”, try to drag the 2nd tab - it will be cut off).

EDIT: Removed unnecessary use of local:TabViewStackPanel, replaced by normal StackPanel

Issue Analytics

  • State:open
  • Created 7 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Gillibaldcommented, May 30, 2023

I think the visual should be rendered with its original size but not with the original relative position.

https://github.com/AvaloniaUI/Avalonia/blob/5eeedbbf88787191adb9262b5689d65284a870b2/src/Avalonia.Base/Media/VisualBrush.cs#L98

The brush itself can still be translated to an individual position if needed.

0reactions
warappacommented, Jul 1, 2023

Is there any chance for this to get fixed before v11 as the final release candidate is published?

As mentioned initially, this impacts dragging tabs in FluentAvalonia’s TabView. And IMHO FluentAvalonia is already an awesome demo of what Avalonia can do for Windows style (x-plat) apps, even more so with fewer bugs 😉.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to control a MediaElement inside of a VisualBrush
I have a MediaElement inside of a VisualBrush object so that I can run multiple video displays while only using one MediaElement.
Read more >
Images and image brushes - Windows apps
An Image object renders an image, and an ImageBrush object paints ... have any control over the viewport like you do with a...
Read more >
Visual Brush In WPF
VisualBrush is a new addition to the brush types since GDI+. ... The Visual property of VisualBrush sets the visual and it can...
Read more >
Painting with Images, Drawings, and Visuals - WPF .NET ...
This topic describes how to use ImageBrush, DrawingBrush, and VisualBrush objects to paint an area with an image, a Drawing, or a Visual....
Read more >
Image Brush Drawing Brush and Visual Brush - Visual Studio
VisualBrush allows us to use any UI element as the brush image— we can ... If you want more precise control, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found