views:

168

answers:

2

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?

A: 

Add Grid and this Set Vertical alligment to Top and Horizontal alignment to Right Sample code

  <VisualBrush x:Key="myVisual">
        <VisualBrush.Visual>
            <Grid>
                <Rectangle Height="200" Width="200" Fill="Red" HorizontalAlignment="Right"  VerticalAlignment="Top" ></Rectangle> 
            </Grid>
        </VisualBrush.Visual>
    </VisualBrush>
Firoz
+1  A: 

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>
Mark Heath
Works perfectly. Thanks a lot.
Holli