Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent the Visual Brush from stretching its content

Tags:

wpf

In my project I want to display a small logo on the side of a custom control. Since I have no canvas I thought maybe a Visual Brush would be a good Idea to place the logo in the background.

<VisualBrush>
    <VisualBrush.Visual>
        <Rectangle Width="200" Height="200" Fill="Red" />
    </VisualBrush.Visual>                
</VisualBrush>

But the Rectangle I am using right now is not 200x200. It takes the complete available space. Thats not what I want. I also tried a Viewbox and set the stretch property but the result is the same because in the end I don't need a simple Rectangle but a canvas with many path objects as children. A Viewbox supports only one child.

This there any way to get around this problem?

like image 929
TalkingCode Avatar asked Oct 01 '09 15:10

TalkingCode


1 Answers

You need to set TileMode, Stretch, AlignmentX and AlignmentY properties on your VisualBrush:

<VisualBrush TileMode="None" Stretch="None" AlignmentX="Left" AlignmentY="Top">
    <VisualBrush.Visual>
        <Rectangle Height="200" Width="200" Fill="Red"></Rectangle> 
    </VisualBrush.Visual>
</VisualBrush>
like image 120
Mark Heath Avatar answered Nov 12 '22 08:11

Mark Heath