2014-09-04 17 views
0

所以我有一個按鈕,其中背景需要匹配一個RadioButton前景色。 我已經編輯按鈕的模板一輪有其邊角,價值標籤在這裏:我如何匹配一個按鈕的背景顏色與另一個項目的前景

<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground"> 
    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneButtonBasePressedForegroundColor}"/> 
</ObjectAnimationUsingKeyFrames> 

我不知道是什麼改變,我甚至試圖改變它時,按鈕像這樣按下:

private void seeWhy_Click(object sender, RoutedEventArgs e) 
    { 
     Button button = sender as Button; 
     button.Background = checkedRadioButton.Foreground; 
     NavigationService.Navigate(new Uri("/quiz.xaml", UriKind.Relative)); 
    } 

回答

0

我假設你有多個具有不同顏色的RadioButton,並希望根據所選顏色更改一個按鈕的背景顏色。

無論如何,即使我錯了,這應該仍然有幫助。

我建議增加的構造過程中的事件處理程序以及存儲按鈕

coolButton = button1; 
radioButton1.Checked += changeColor; 
radioButton2.Checked += changeColor; 

然後事件處理程序:

private void changeColor(Object sender, RoutedEventArgs e) 
{ 
    coolButton.Background = ((RadioButton) sender).Foreground; 
} 
相關問題