在Datagrid中单击事件中的更改图像按钮 [英] Change image button in click event in Datagrid

查看:94
本文介绍了在Datagrid中单击事件中的更改图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在设计wpf应用程序。在我的应用程序中,我有一个父子数据网格,每行都有一个展开按钮。当我单击该按钮时,子网格会扩展,此时我想更改按钮的图像,即折叠符号。请让我知道如何在其点击事件中更改按钮的图像。请参阅我的xaml代码





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


<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>

推荐答案

你只是想做一半的工作,你可以愤怒的图像,但工具提示仍然会读取展开,大概你的点击甚至可以处理不同的状态。



你有2个选择,构建2个具有不同功能的按钮并管理Visible属性。或者将工具提示和图像属性绑定到数据集合,允许更改事件触发数据更改。



我有理由相信有一些错综复杂的XAML方法这样做,有人可能会指出。此外,控件本身可能有一个展开/折叠事件,您可以挂钩以控制内容。
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.


这篇关于在Datagrid中单击事件中的更改图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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