【问题标题】:How to find id in silverlight data grid如何在 Silverlight 数据网格中查找 id
【发布时间】:2012-05-04 14:39:36
【问题描述】:

我需要获取放置在数据模板中的图像的 ID。代码如下。

<sdk:DataGrid.Columns>
 <sdk:DataGridTemplateColumn x:Name="colDeleteContent" IsReadOnly="True" Header="Delete Content" Width="100" CanUserResize="False">
   <sdk:DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
         <StackPanel x:Name="spDeleteContent" VerticalAlignment="Center" Margin="10,0,0,0" Width="20" Height="20" HorizontalAlignment="Center" Orientation="Vertical">
             <Image x:Name="imgDeleteContent" Source="Assets/Images/close.png" Height="15" Tag="Assets/Images/close.png" Width="15" Margin="0" Cursor="Hand" Opacity="0" />
         </StackPanel>
       </DataTemplate>
     </sdk:DataGridTemplateColumn.CellTemplate>
   </sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>

我需要获取“imgDeleteContent”的 ID,该 ID 已放置在我的代码后面的数据模板堆栈面板中。

请帮忙,谢谢

【问题讨论】:

  • 你知道行的索引,你要查找的图像吗?
  • @vorrtex 我不知道该行的索引,我没有明白你的意思。该图像位于数据网格的第零(0)列。感谢您的回复。
  • 首先,您应该按索引检索行,示例如下:stackoverflow.com/a/4065667/427225。然后您应该检索单元格值,如下所示:stackoverflow.com/a/3121715/427225。之后,您可以尝试将元素投射到 StackPanel 并找到图像。但是使用视图模型和数据绑定会更容易更好。

标签: silverlight


【解决方案1】:

您可以在网格加载行事件中找到控件名称,如下所示

StackPanel Sp = grdProducts.Columns[1].GetCellContent(e.Row) as StackPanel;

然后使用快速查看找到该 imgDeleteContent 控件。做任何你喜欢的事:)

【讨论】:

    猜你喜欢
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    相关资源
    最近更新 更多