开发者

Locate position of control that was clicked in GridView (WPF)

开发者 https://www.devze.com 2023-03-20 05:25 出处:网络
I\'m using a ListView that contains a GridView, there\'s a gridviewcolumn which only contains buttons. In the buttonclick event, how do I get the position (I just need the row in this case) of the but

I'm using a ListView that contains a GridView, there's a gridviewcolumn which only contains buttons. In the buttonclick event, how do I get the position (I just need the row in this case) of the button which fired the event?

<ListView.View>
<GridView>
<GridViewColumn Width="Auto">
        <GridViewColumn.CellTemplate>
        <DataTemplate>
        <Button Width="Auto" Height="Auto" Background="#00000000" BorderBrush="#00000000" BorderThickness="0" Click="Finalizado_Click">
        <Button.Content>
            <Image Source="Content/okay.png" Width="8" Height="8"/>
        </Button.Content>
        </Button>
  开发者_运维百科      </DataTemplate>
        </GridViewColumn.CellTemplate>
 </GridViewColumn>


I know the columns are automatically autogeneratedfields, if you change them to buttonfields you might be able to get a little more information. Sorry I can't help more than that.


public ListViewItem GetRow(DependencyObject item)
{
    DependencyObject dObj = VisualTreeHelper.GetParent(item);
    if (dObj == null)
        return null;

    if (dObj is ListViewItem)
        return dObj as ListViewItem;

    return GetRow(dObj);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消