XAML ListView

The <ListView> element represents a WPF ListView control in XAML. 
  1. <ListView />  
The code example in the following list creates a ListView and sets its properties. 
  1. <ListView Margin="10,10,0,13" Name="ListView1" HorizontalAlignment="Left"  
  2. VerticalAlignment="Top" Width="200" Height="300" />  
The ListViewItem item represents an item of ListView. The following code example adds several items to a ListView. 
  1. <ListView Margin="10,10,0,13" Name="ListView1" HorizontalAlignment="Left"  
  2. VerticalAlignment="Top" Width="194" Height="200">  
  3. <ListViewItem Content="Coffie"></ListViewItem>  
  4. <ListViewItem Content="Tea"></ListViewItem>  
  5. <ListViewItem Content="Orange Juice"></ListViewItem>  
  6. <ListViewItem Content="Milk"></ListViewItem>  
  7. <ListViewItem Content="Iced Tea"></ListViewItem>  
  8. <ListViewItem Content="Mango Shake"></ListViewItem>  
  9. </ListView>  
The Foreground and Background attributes of a ListViewItem represents the background and foreground colors of the item. The following code snippet sets the background and foreground colors of a ListViewItem. 
  1. <ListViewItem Background="LightCoral" Foreground="Red" Content="Coffie"></ListViewItem>  
The FontFamily, FontSize and FontWeight are used to set a font of a ListViewItem. The following code snippet sets font verdana, size 12 and bold of a ListViewItem. 
  1. <ListViewItem Background="LightCoral" Foreground="Red" Content="Coffie"  
  2. FontFamily="Verdana" FontSize="12" FontWeight="Bold"></ListViewItem>  
  3. I set the following properties of ListViewItems.  
  4. <ListViewItem Background="LightCoral" Foreground="Red" Content="Coffie"  
  5. FontFamily="Verdana" FontSize="12" FontWeight="Bold"></ListViewItem>  
  6. <ListViewItem Background="LightGray" Foreground="Black" Content="Tea"  
  7. FontFamily="Georgia" FontSize="14" FontWeight="Bold"></ListViewItem>  
  8. <ListViewItem Background="LightBlue" Foreground="Purple" Content="Orange Juice"  
  9. FontFamily="Verdana" FontSize="12" FontWeight="Bold"></ListViewItem>  
  10. <ListViewItem Background="LightGreen" Foreground="Green" Content="Milk"  
  11. FontFamily="Georgia" FontSize="14" FontWeight="Bold"></ListViewItem>  
  12. <ListViewItem Background="LightBlue" Foreground="Blue" Content="Iced Tea"  
  13. FontFamily="Verdana" FontSize="12" FontWeight="Bold"></ListViewItem>  
  14. <ListViewItem Background="LightSlateGray" Foreground="Orange" Content="Mango Shake"  
  15. FontFamily="Georgia" FontSize="14" FontWeight="Bold"></ListViewItem>  
Here is a detailed tutorial on ListView: WPF ListView Tutorial.  

Recommended Free Ebook
Similar Articles
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.