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.

有帮助吗?

解决方案

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top