Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am programming a game for my project at school and I am having trouble with handling the buttons click.

When the buttons are clicked I want to change the (background)color of the button. But I unable to change it from my C#-code.
I have used a template for my buttons but I can't change the color from xaml or C#

Can you help me please?

Nico
XML
<Style TargetType="s:SurfaceButton"  x:Key="dorpje">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="s:SurfaceButton">
                       <Grid>
                            <Ellipse x:Name="Ell" Width="15" Height="15" Stroke="Black" Fill="WhiteSmoke">
                                <Ellipse.BitmapEffect>
                                    <DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
                                </Ellipse.BitmapEffect>
                            </Ellipse>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
Posted
Updated 9-Jun-10 4:51am
v2

1 solution

Do you mean change color while the left mouse button is down, or change color permenantly after it's clicked?

For the first choice, you need to add a trigger (in your XAML) that changes the color when the button is pressed. In the second, you could bind the button's Background property to a property in the form that's set when the button is clicked. You probably have to derive your form from INotifyPropertyChanged in order to get that binding to work.
 
Share this answer
 
Comments
Nicotjai 9-Jun-10 12:25pm    
Sorry I wasn't very clear, it's to change the color permanently.
But the problem is that when I use:
Button.Background = Brush.Black;
I can't change the color into another one

And it's supposed to be surfacebutton maybe that's one of the problem too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900