& lt按鈕。資源& gt& ltSolidCo" />
前臺:
& lt網格& gt
& ltbutton Name = " BTN " Width = " 80 " Height = " 30 " >
& lt按鈕。資源& gt
& ltSolidColorBrush x:Key = " Red brush " Color = " Red "/& gt;
& ltSolidColorBrush x:Key = " greenbrush " Color = " Green "/& gt;
& lt/按鈕。資源& gt
& lt按鈕。模板& gt
& ltControlTemplate & gt
& ltrectangle Name = " RCT " Fill = " { static resource red brush } "/& gt;
& lt/control template & gt;
& lt/按鈕。模板& gt
& lt/Button & gt;
& ltButton Click = " Button 1 _ Click " Content = " Button " Height = " 23 " horizontal alignment = " Left " Margin = " 190,222,0,0 " Name = " Button 1 " vertical alignment = " Top " Width = " 75 "/>
& lt/Grid & gt;
後臺:
私有void button1_Click(對象發送方,RoutedEventArgs e)
{
矩形rec = (Rectangle)btn。Template.FindName("rct ",BTN);
建議。SetResourceReference(矩形。FillProperty,“green brush”);
}