按钮背景问题(与先前询问的问题有关) [英] Button Background problem (related to previously asked question)

查看:77
本文介绍了按钮背景问题(与先前询问的问题有关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与先前未解决的问题有关,将背景分配给按钮控件时出现的问题 [

This question is related to previously asked question which wasn''t solved Problem when assigning Background to Button control[^]

Starting from a scratch windows phone silverlight application. I added three buttons, button1, button2, and button3. I wrote the following code in the button1_click event handler.

private void button1_Click(object sender, RoutedEventArgs e)
       {

           button1.Background = new SolidColorBrush(Colors.Red);
           button2.Background = new SolidColorBrush(Colors.Brown);
           button3.Background = new SolidColorBrush(Colors.Yellow);

       }



仅更改button2和button3的背景,但不更改button1的背景.可能是什么问题?请帮助



Only button2 and button3 ''s background is changed, but button1''s background is not altered. What can be the problem? Please help

推荐答案

问题已解决!

代替更改实际背景本身,使用背景参考可以解决问题.

Problem solved!!

Instead of changing the actual background itself, using the reference of the background solves the problem.

private void HighlightButton(Button btnToHighlight)
        {

            SolidColorBrush sBrush = (SolidColorBrush)btnToHighlight.Background;


            sBrush.Color = //enter your colour here
            btnToHighlight.Background = sBrush;

        }



为所有按钮实现了这一点.瞧!



Implemented this for all the buttons. Voila!!!


这篇关于按钮背景问题(与先前询问的问题有关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆