Вопрос

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