Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Create A GridView In XAML
WhatsApp
Mahesh Chand
6y
65.6k
0
5
100
Article
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.
<ListView.View>
<GridView />
</ListView.View>
</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.
<
GridView
AllowsColumnReorder
=
"true"
ColumnHeaderToolTip
=
"Authors"
>
<
GridViewColumn
Header
=
"Name"
Width
=
"120"
DisplayMemberBinding
=
"{Binding Path=Name}"
/>
<
GridViewColumn
Header
=
"Age"
Width
=
"50"
DisplayMemberBinding
=
"{Binding Path=Age}"
/>
<
GridViewColumn
Header
=
"Book"
Width
=
"250"
DisplayMemberBinding
=
"{Binding Path=Book}"
/>
<
GridViewColumn
Header
=
"MVP"
Width
=
"50"
DisplayMemberBinding
=
"{Binding Path=Mvp}"
/>
</
GridView
>
To avoid content duplication, the article has moved here:
WPF GridView Tutorial
.
XAML GridView
Up Next
Ebook Download
View all
Programming XAML
Read by 12.3k people
Download Now!
Learn
View all
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.
Membership not found