How To Create A GridView In XAML

XAML doesn't support a GridView element. However, you can use a ListView to create a GridView like UI. The code sample in this article is an example of creating GridView in XAML. You can learn more about ListView control here: ListView in WPF.
 
The key of supporting a GridView is the View property of ListView.
 
The following code snippet sets the View property of a ListView to GridView mode. 
  1.     <ListView.View>  
  2.         <GridView />  
  3.      </ListView.View>  
  4. </ListView>  
A GridView is used as a supplemental control to a ListView to provide style and layout. The GridView does not have its own control-related properties such as background and foreground colors, font properties, size and location. The container ListView is used to provide all the control related properties. The GridView element in XAML represents a GridView at design-time.
 
The Columns property of GridView returns a collection of GridViewColumn objects. A GridViewColumn element in XAML represents a GridView column. The AllowsColumnReorder property represents whether columns in a GridView can be reordered by a user by dragging and dropping from one position to another. The ColumnHeaderToolTip property represents the content of a tooltip that appears when the mouse pointer pauses over one of the column headers.
 
The following code sample creates a GridView control and adds four columns to it. The Header property of GridViewColumn represents the header of a column. The Width property represents the width of a column and the DisplayMemberBinding property is used to bind a GridViewColumn to a property of data binding object.  
  1. <GridView AllowsColumnReorder="true" ColumnHeaderToolTip="Authors"    
  2.           >    
  3. <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Path=Name}" />    
  4.     <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Path=Age}" />    
  5.     <GridViewColumn Header="Book" Width="250" DisplayMemberBinding="{Binding Path=Book}" />    
  6.     <GridViewColumn Header="MVP" Width="50" DisplayMemberBinding="{Binding Path=Mvp}" />    
  7.         
  8. </GridView>    
To avoid content duplication, the article has moved here: WPF GridView Tutorial.  


Recommended Free Ebook
Similar Articles
Mindcracker
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.