Question

I've got a rectangle in a button and want to change it's color. How can i Do that?

<Button Click="btnInitial_Click" Margin="0, 5, 0,0" Grid.Row="3" Grid.Column="3" Name="btnInitial">
       <Button.Template>
            <ControlTemplate>
                <Rectangle Name="rectInitial" Stroke="Black" Fill="#4169e1"></Rectangle>
            </ControlTemplate>
       </Button.Template>
</Button>

//EDIT: I want to change it in its own Click Event.

Was it helpful?

Solution

There are many ways to do so, depending on where you want to set it. If you want to set it from code-behind you can to it like this:

var rect = btnInitial.Template.FindName("rectInitial") as Rectangle;
rect.Fill = Brushes.Aquamarine;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top