Create a ListView control that implements a GridView view with CheckBox controls for each row. : ListView « Windows Presentation Foundation « C# / CSharp Tutorial






<Window x:Class="SDKSample.Window1"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Window.Resources>
    <XmlDataProvider x:Key="MyData" XPath="/Info">
      <x:XData>
        <Info xmlns="">
          <Song Name="Song 1"/>
          <Song Name="Song 2"/>
          <Song Name="Song 3"/>
        </Info>
      </x:XData>
    </XmlDataProvider>
    <Style x:Key="MyContainer" TargetType="{x:Type ListViewItem}">
      <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="true">
          <Setter Property="Foreground" Value="Blue" />
          <Setter Property="Cursor" Value="Hand"/>
        </Trigger>
        <MultiTrigger>
          <MultiTrigger.Conditions>
            <Condition Property="IsSelected" Value="true" />
            <Condition Property="Selector.IsSelectionActive" Value="true" />
          </MultiTrigger.Conditions>
          <Setter Property="Foreground" Value="Yellow" />
        </MultiTrigger>
      </Style.Triggers>
    </Style>
    <DataTemplate x:Key="FirstCell">
      <StackPanel Orientation="Horizontal">
        <CheckBox IsChecked="{Binding Path=IsSelected, 
          RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"/>
      </StackPanel>
    </DataTemplate>
  </Window.Resources>
  <StackPanel>
    <ListView ItemsSource="{Binding Source={StaticResource MyData}, XPath=Song}" 
           ItemContainerStyle="{StaticResource MyContainer}" 
           SelectionMode="Single" 
           Name="myPlaylist">
      <ListView.View>
        <GridView>
          <GridViewColumn CellTemplate="{StaticResource FirstCell}" Width="30"/>
          <GridViewColumn Header="Name" DisplayMemberBinding="{Binding XPath=@Name}" Width="80"/>
        </GridView>
      </ListView.View>
    </ListView>
  </StackPanel>
</Window>
WPF Create A List View Control That Implements A Grid View View With Check Box Controls For Each Row








24.34.ListView
24.34.1.Create a ListView control that implements a GridView view with CheckBox controls for each row.Create a ListView control that implements a GridView view with CheckBox controls for each row.
24.34.2.Use ArrayList as the ListView ItemSourceUse ArrayList as the ListView ItemSource
24.34.3.Create a ListView control that implements a GridView view mode, displays content in groups.Create a ListView control that implements a GridView view mode, displays content in groups.
24.34.4.ListView and ListViewItemListView and ListViewItem
24.34.5.ListView columnsListView columns
24.34.6.Populating ListView rowsPopulating ListView rows
24.34.7.Set Binding ListView.ItemsSourceProperty to ListViewSet Binding ListView.ItemsSourceProperty to ListView
24.34.8.Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.Create a ListView control that uses a GridView view mode to display a collection of DateTime objects.
24.34.9.ListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate propertiesListView using GridView.HeaderTemplate and GridViewColumn.CellTemplate properties
24.34.10.Get Bounded item from ListViewGet Bounded item from ListView
24.34.11.Create Binding for ListView in codeCreate Binding for ListView in code
24.34.12.Use three TextBlocks in one ListViewItemUse three TextBlocks in one ListViewItem
24.34.13.Create a ListView control that uses a GridView view mode to display dates.Create a ListView control that uses a GridView view mode to display dates.
24.34.14.Use Path to reference Bounded object in ItemSourceUse Path to reference Bounded object in ItemSource
24.34.15.Enables sorting of data in ascending or descending order according to the contents of one column.Enables sorting of data in ascending or descending order according to the contents of one column.