Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,
I am designing wpf application. In my application I have a "Parent-Child" data grid and I have a expand button in each row. when I click that button the child grid expands and at that time I want to change the image of the button ie "Collapse" symbol. Please let me know how to change the image of a button in its click event. Please see my xaml code


XML
<DataGridTemplateColumn Header="C" >
      <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                   <StackPanel Name="stk">
                      <Button x:Name="btnCollapse"  ToolTip="Expand" Foreground="Black"  Click="btnCollapse_Click"  >
                      <Image Source="../images/Plus.png" Cursor="Hand"  Height="20" Width="15"  Name="imgExpandGrid" ></Image>
                      </Button>
                   </StackPanel>
              </DataTemplate>
         </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Posted
Updated 24-Nov-13 20:41pm
v2

1 solution

You are only attempting to do half the job, you can change the image but the tooltip will still read Expand, presumably your click even handles the different states.

You have 2 choices, build 2 buttons with the different functionality and manage the Visible attribute. Or bind the tooltip and image attributes to the data collection, allowing the change event to trigger the data change.

I'm reasonably sure there are some intricate XAML method of doing this which someone may be able to point out. Also the control itself may have an expand/collapse event you can hook into to control the content.
 
Share this answer
 
Comments
jing567 25-Nov-13 3:34am    
Hello,
Can yuo give me an implemented code if you have please...
Mycroft Holmes 25-Nov-13 4:08am    
Nope - that is your job. Take a look through some of the examples, there are plenty around.

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