Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I have a button with a gray image in a rectangle. What I want, is that when I click on it, the button change to a blue image.

How Do I do That?

Any suggestion will be appreciated


XML
<Button x:Name="botonAlumnos" DockPanel.Dock="Top" Click="botonAlumnos_Click">
   <Button.Template>
        <ControlTemplate>
           <Rectangle x:Name="rect1" Height="125" Width="125">
              <Rectangle.Fill>
                 <ImageBrush ImageSource="{DynamicResource _Alumnos}"/>
              </Rectangle.Fill>
           </Rectangle>
        </ControlTemplate>
   </Button.Template>
</Button>


________________________________

Now I founded this on the web

C#
private void botonAlumnos_Click(object sender, RoutedEventArgs e)
{
 var rect1 = botonAlumnos.Template.FindName("rectAlumnos", botonAlumnos) as Rectangle;
 rect1.Fill = Brushes.White;
}


With this code the Rectangle turns White. What I want is fill it with a picture.
Posted
Updated 4-Nov-14 11:01am
v2
Comments
Sergey Alexandrovich Kryukov 4-Nov-14 17:25pm    
What's wrong with just reading original MSDN documentation?
—SA

1 solution

Please see my comment to the question. Please see: http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28v=vs.110%29.aspx[^].

Note that you already had it in XAML. And every element and attribute in XAML is documented in MSDN.

—SA
 
Share this answer
 
Comments
Maciej Los 4-Nov-14 18:01pm    
As my Maestro said: it should be quite enough ;)
MSDN documentation is always good point to start.
+5!
Sergey Alexandrovich Kryukov 4-Nov-14 18:39pm    
Thank you, Maciej.
—SA

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