繁体   English   中英

如何将按钮的背景颜色与另一个项目的前景匹配

[英]How can i match the background color of a button with the foreground of another item

因此,我有一个按钮,其中背景需要与RadioButton前景色匹配。 我已经编辑了按钮的模板,使其在这里的Value标记下具有圆角:

<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));
    }

我假设您有多个具有不同颜色的RadioButton,并希望根据所选颜色更改一个按钮的背景颜色。

无论如何,即使我错了,这仍然会有所帮助。

我建议在构造函数期间添加事件处理程序以及存储按钮

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

然后是事件处理程序:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM