如何从其子控件访问ListViewItem?

时间:2015-09-13 12:16:11

标签: c# wpf listviewitem

我有一些ListViewItem来自一个集合,我创建了一个DataTemplate,以便每个ListViewItem都有一个Button作为子控件:

<Window.Resources>
    <DataTemplate x:Key="ItemTemplate_AwesomeTemplate">
        <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
            <Button Content="Awesome Button" Click="Awesome_Button_Click" HorizontalContentAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Foreground="Black"/>
        </StackPanel>
    </DataTemplate>
</Window.Resources>

<ListView x:Name="AwesomeListView" HorizontalAlignment="Left"  Height="577" VerticalAlignment="Top" Width="934" ScrollViewer.HorizontalScrollBarVisibility="Visible" Foreground="Black" Margin="10,10,0,0">
  <ListView.View>
    <GridView>
       <GridViewColumn Header="AwesomeHeader" Width="250" CellTemplate="{StaticResource ItemTemplate_AwesomeTemplate}"/>
    </GridView>
  </ListView.View>
</ListView>

当我点击某个Button时,是否可以更改包含所点击的IsSelected的{​​{1}}的{​​{1}}属性?

1 个答案:

答案 0 :(得分:2)

要更改包含所点击的IsSelected的{​​{1}}的{​​{1}} 属性,您应该使用ListViewItem来查找此类项目:

Button