[C#/UWP] ListView 엘리먼트 : 필터 사용하기


■ ListView 엘리먼트에서 필터를 사용하는 방법을 보여준다.

GroupInfoList.cs

▶ Contact.cs
—————————————————————————————————-
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Windows.Storage;

namespace TestProject
{
/// <summary>
/// 연락
/// </summary>
public class Contact
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public

#region 이름 – FirstName

/// <summary>
/// 이름
/// </summary>
public string FirstName { get; private set; }

#endregion
#region 성 – LastName

/// <summary>
/// 성
/// </summary>
public string LastName { get; private set; }

#endregion
#region 회사 – Company

/// <summary>
/// 회사
/// </summary>
public string Company { get; private set; }

#endregion
#region 성명 – Name

/// <summary>
/// 성명
/// </summary>
public string Name => FirstName + " " + LastName;

#endregion

//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public

#region 생성자 – Contact(firstName, lastName, company)

/// <summary>
/// 생성자
/// </summary>
/// <param name="firstName">이름</param>
/// <param name="lastName">성</param>
/// <param name="company">회사</param>
public Contact(string firstName, string lastName, string company)
{
FirstName = firstName;
LastName = lastName;
Company = company;
}

#endregion

//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public

#region 컬렉션 구하기 (비동기) – GetCollectionAsync()

/// <summary>
/// 컬렉션 구하기 (비동기)
/// </summary>
/// <returns>컬렉션</returns>
public static async Task<ObservableCollection<Contact>> GetCollectionAsync()
{
StorageFile storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///DATA/Contacts.txt"));

IList<string> lineList = await FileIO.ReadLinesAsync(storageFile);

ObservableCollection<Contact> collection = new ObservableCollection<Contact>();

for(int i = 0; i < lineList.Count; i += 3)
{
collection.Add(new Contact(lineList[i], lineList[i + 1], lineList[i + 2]));
}

return collection;
}

#endregion
#region 그룹 컬렉션 구하기 (비동기) – GetGroupCollectionAsync()

/// <summary>
/// 그룹 컬렉션 구하기 (비동기)
/// </summary>
/// <returns>그룹 컬렉션</returns>
public static async Task<ObservableCollection<GroupInfoList>> GetGroupCollectionAsync()
{
IEnumerable<GroupInfoList> query = from item in await GetCollectionAsync()
group item by item.LastName.Substring(0, 1).ToUpper() into itemGroup
orderby itemGroup.Key
select new GroupInfoList(itemGroup) { Key = itemGroup.Key };

return new ObservableCollection<GroupInfoList>(query);
}

#endregion
#region 문자열 구하기 – ToString()

/// <summary>
/// 문자열 구하기
/// </summary>
/// <returns>문자열</returns>
public override string ToString()
{
return Name;
}

#endregion
}
}
—————————————————————————————————-

MainPage.xaml

MainPage.xaml.cs

TestProject.zip

분류

보관함