티스토리 뷰
http://www.wpf-tutorial.com/listview-control/listview-grouping/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <Grid Margin="10"> <ListView Name="lvUsers"> <ListView.View> <GridView> <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" /> </GridView> </ListView.View> <ListView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock FontWeight="Bold" FontSize="14" Text="{Binding Name}"/> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListView.GroupStyle> </ListView> </Grid> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); List<User> items = new List<User>(); items.Add(new User() { Name = "John Doe", Age = 42, Sex = SexType.Male }); items.Add(new User() { Name = "Jane Doe", Age = 39, Sex = SexType.Female }); items.Add(new User() { Name = "Sammy Doe", Age = 13, Sex = SexType.Male }); lvUsers.ItemsSource = items; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource); PropertyGroupDescription groupDescription = new PropertyGroupDescription("Sex"); view.GroupDescriptions.Add(groupDescription); } } public enum SexType { Male, Female }; public class User { public string Name { get; set; } public int Age { get; set; } public string Mail { get; set; } public SexType Sex { get; set; } } } | cs |
1 2 3 4 | <ListView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> | cs |
<TextBlock Text="{Binding Name}"/>TextBlock의 Text는 Name에 바인딩이 되어있는 상태이지만, data 객체는 Name 속성이 아닙니다.
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource);
ItemsSources를 할당한 후에는 ListView가 생성한 CollectionView를 이용합니다.
Customizing the group header
어.. 뭐지.. 좀 복잡하다 계속 공부해봐야겠습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <Grid Margin="10"> <ListView Name="lvUsers"> <ListView.View> <GridView> <GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Header="Age" Width="50" DisplayMemberBinding="{Binding Age}" /> </GridView> </ListView.View> <ListView.GroupStyle> <GroupStyle> <GroupStyle.ContainerStyle> <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Expander IsExpanded="True"> <Expander.Header> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="Gray" FontSize="22" VerticalAlignment="Bottom" /> <TextBlock Text="{Binding ItemCount}" FontSize="22" Foreground="Green" FontWeight="Bold" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" /> <TextBlock Text=" item(s)" FontSize="22" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" /> </StackPanel> </Expander.Header> <ItemsPresenter /> </Expander> </ControlTemplate> </Setter.Value> </Setter> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </ListView.GroupStyle> </ListView> </Grid> | cs |
'C# > WPF' 카테고리의 다른 글
MVVM 예제1 (0) | 2017.07.09 |
---|---|
WPF tutorial - ListView sorting (0) | 2017.07.04 |
WPF tutorial - How-to: ListView with left aligned column names (0) | 2017.07.03 |
WPF tutorial - ListView with a GridView (0) | 2017.07.03 |
WPF tutorial - ListView, data binding and ItemTemplate (0) | 2017.07.03 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- UIView Animation
- 문자열
- listview
- MVVM
- FEED
- command
- 코딩야학
- C++
- DP
- 데이터 바인딩
- 스택
- Fakebook
- dfs
- 백준
- 백준온라인
- 타일링
- 생활코딩
- Grid
- 객체
- Cell Animation
- 그래프
- CustomCollectionViewCell
- Custom Cell
- BOJ
- Add TapGesture
- XAML
- WPF
- BFS
- CollectionView
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
글 보관함