Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid with background image and color

Is it possible to give an entire grid in xaml both a background image and a color? I am not scaling the image so there are regions that do not have a color. Is it possible to color the rest of the grid in a color?

This is my current code:

<Grid>
            <Grid.Background>
                <ImageBrush Stretch="None" ImageSource="Images/background_top.png" AlignmentY="Top" AlignmentX="Center"/>
            </Grid.Background>

        <Grid.RowDefinitions>
            <RowDefinition Height="50*" />
            <RowDefinition Height="50*" />
        </Grid.RowDefinitions>
    </Grid>
like image 450
Jerodev Avatar asked Dec 29 '12 19:12

Jerodev


People also ask

How use background Image in css in Grid?

Use the CSS style to change the background images of a webpage. Make sure the property background-image is inserted in the CSS *style> tag. HTML5 does not allow the body> background attribute. In order to change a set background image using HTML5, you use CSS.

How do you change the grid background?

In Edit mode, tap on the grid icon next to the settings cog and select Grid Background. Here you can choose a colour or picture for the background of your grid set.


1 Answers

The only way that I can think of is to use the Background Property to set the Color, then add an Image to the Grid making sure to span all of your Rows and Columns. As long as the Image is the first Item in your grid the others will be layered on top. I beleive it will give you the effect you are looking for.

<Grid Background="Red">
    <Image Grid.RowSpan="2" Stretch="None" Source="Images/background_top.png" VerticalAlignment="Top" HorizontalAlignment="Center"/>
    <Label Content="Label" Grid.Row="0" Height="28" HorizontalAlignment="Center"  Margin="10,10,0,0" Name="label1" VerticalAlignment="Top" />
    <Grid.RowDefinitions>
        <RowDefinition Height="50*" />
        <RowDefinition Height="50*" />
    </Grid.RowDefinitions>
</Grid>
like image 99
Mark Hall Avatar answered Oct 09 '22 19:10

Mark Hall