Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting ContentControl's background color in XAML

For the life of me I cant seem to figure out this simple task of setting the ContentControl's background color:

<ContentControl x:Name="Content03"
            Width="130"
            Height="130"
            Canvas.Top="50"
            Canvas.Left="400"
            Background="Yellow">
        <Ellipse Fill="YellowGreen" IsHitTestVisible="True">
        </Ellipse>
    </ContentControl>

Also tried doing this using styles but still doesnt work ;(

like image 674
Tim Robbins Avatar asked Dec 20 '22 06:12

Tim Robbins


1 Answers

A ContentControl has no visual prescence in itself, but is a container for a child control. Setting some properties on this control (like fontsize etc) is usually only a way of having those properties propagate down the visual tree, so they van be picked up by child controls (those that support it).

The best thing to do is this:

<ContentControl x:Name="Content03"
            Width="130"
            Height="130"
            Canvas.Top="50"
            Canvas.Left="400">
        <Grid Background="Yellow">
        <Ellipse Fill="YellowGreen" IsHitTestVisible="True">
        </Ellipse>
        </Grid>
    </ContentControl>
like image 166
Dean Chalk Avatar answered Jan 05 '23 14:01

Dean Chalk