WPF-带有GridView的ListView样式

ListView是展示数据的常用控件,这里简单对带有GridView的ListView样式进行设置。

 
        
        
        

此样式设置了表头样式,和表的每一行样式。

 
        <ListView
            x:Name="lvUsers"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
           >
            
                "{StaticResource HeadStyle}">
                    <GridViewColumn
                        Width="120"
                        DisplayMemberBinding="{Binding Name}"
                        Header="Name" />
                    <GridViewColumn
                        Width="50"
                        DisplayMemberBinding="{Binding Age}"
                        Header="Age" />
                    <GridViewColumn
                        Width="150"
                        DisplayMemberBinding="{Binding Mail}"
                        Header="Mail" />
                
            
        
    

 

.cs文件

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            List items = new List();
            items.Add(new User() { Name = "John Doe", Age = 42, Mail = "[email protected]" });
            items.Add(new User() { Name = "Jane Doe", Age = 39, Mail = "[email protected]" });
            items.Add(new User() { Name = "Sammy Doe", Age = 7, Mail = "[email protected]" });
            lvUsers.ItemsSource = items;
        }
    }
    public class User
    {
        public string Name { get; set; }

        public int Age { get; set; }

        public string Mail { get; set; }
    }

效果图:

WPF-带有GridView的ListView样式_第1张图片

 

你可能感兴趣的:(WPF-带有GridView的ListView样式)