문제

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