質問

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