listview的gridview视图中,获取列中模板内的button按钮(找控件内的控件)

 

点击“间隙”,获取“间隙”旁边隐藏的减号按钮(本图片未显示出来)

private void TextBlock_MouseDown_2(object sender, MouseButtonEventArgs e)
{
ContentPresenter contentPres = (sender as FrameworkElement).TemplatedParent as ContentPresenter;
DataTemplate dTemplate = contentPres.ContentTemplate;
Button quesDesc = (Button)dTemplate.FindName("delete", contentPres)

.......

}

xaml

<ListView Name="listview" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="5" Background="#D8D8D8">
    <ListView.View>
        <GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
            <GridViewColumn Header="类型" Width="80">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <WrapPanel>
                            <TextBlock Text="{Binding Path=ItemType,Converter={StaticResource itemtypeConverter}}" MouseDown="TextBlock_MouseDown_2"></TextBlock>
                            <Button Name="delete" Visibility="Hidden" Content="-" Click="delete_Click_1"></Button>
                        </WrapPanel>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
              </GridViewColumn>
....
        </GridView>
    </ListView.View>
</ListView>

;

posted @ 2019-04-11 15:40  岳凯歌  阅读(167)  评论(0编辑  收藏  举报