[英]How to get the button and change its color when datagrid item selected?
I have a datagrid with button included and binded to image as shown. 我有一个包含按钮的datagrid,并绑定到图像,如图所示。 How to get the button control and change its forecolor when the datagrid item is selected.
选择datagrid项时如何获取按钮控件并更改其前景色。
<DataGrid Name="dgItems" AutoGenerateColumns="False" Grid.Row="1" Width="300" CanUserAddRows="False" SelectionChanged="dgItems_SelectionChanged">
<DataGrid.Columns>
<DataGridTemplateColumn Width="SizeToCells" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Name="btnImg" Click="btnImg_Click" Height="160" Width="270">
<Image Source="{Binding Path=ImgUrl}" />
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
As an example you could do something like this.. 例如,您可以做这样的事情。
row.Cells[2].ButtonName.Style.BackColor = System.Drawing.Color.Red; row.Cells [2] .ButtonName.Style.BackColor = System.Drawing.Color.Red;
This is pseudo-code but you would have to know the actual cell based on the index this should be enough to get you started could you also post the code behind of the event you are trying to code the button change in..? 这是伪代码,但是您将必须基于索引知道实际的单元格,这应该足以使您入门。如果您还要在尝试对按钮更改进行编码的事件后发布代码,则还可以。 thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.