CollectionViewSource 클래스

정의

컬렉션 클래스에 그룹화 및 현재 항목 지원을 추가하는 데이터 원본을 제공합니다.

public ref class CollectionViewSource sealed : DependencyObject
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class CollectionViewSource final : DependencyObject
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class CollectionViewSource final : DependencyObject
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class CollectionViewSource : DependencyObject
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class CollectionViewSource : DependencyObject
Public NotInheritable Class CollectionViewSource
Inherits DependencyObject
<CollectionViewSource .../>
상속
Object Platform::Object IInspectable DependencyObject CollectionViewSource
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

자세한 정보, 디자인 지침 및 코드 예제는 데이터 바인딩 심층 분석을 참조하세요.

WinUI 2 갤러리 앱이 설치된 경우 여기를 클릭하여 앱을 열고 실행 중인 SemanticZoom을 사용하여 그룹화 예제를 확인합니다.

다음 코드 예제에서는 그룹화 LINQ 쿼리의 결과에 ListBox 컨트롤을 바인딩하는 방법을 보여 줍니다(팀 컬렉션은 도시별로 그룹화되고 도시 이름과 함께 그룹 헤더로 표시됨). 전체 코드 목록은 XAML 데이터 바인딩 샘플을 참조하세요.

<Grid>

  <Grid.Resources>
    <CollectionViewSource x:Name="groupInfoCVS" IsSourceGrouped="true"/>
  </Grid.Resources>

  <ListBox x:Name="lbGroupInfoCVS" 
    ItemsSource="{Binding Source={StaticResource groupInfoCVS}}">

    <ListBox.GroupStyle>
      <GroupStyle>
        <GroupStyle.HeaderTemplate>
          <DataTemplate>

            <TextBlock Text="{Binding Key}"/>

          </DataTemplate>
        </GroupStyle.HeaderTemplate>
      </GroupStyle>
    </ListBox.GroupStyle>

    <ListBox.ItemTemplate>
      <DataTemplate>

        <Border Background="{Binding Color}" 
          Width="200" CornerRadius="10" HorizontalAlignment="Left">

          <TextBlock Text="{Binding Name}" 
            Style="{StaticResource DescriptionTextStyle}" 
            HorizontalAlignment="Center" FontWeight="Bold"/>

        </Border>
      </DataTemplate>
    </ListBox.ItemTemplate>

  </ListBox>

</Grid>
Teams teams = new Teams();
var result = 
    from t in teams 
    group t by t.City into g 
    orderby g.Key 
    select g;
groupInfoCVS.Source = result;

자세한 예제는 XAML 데이터 바인딩 샘플을 참조하세요.

설명

컬렉션에 목록 컨트롤을 바인딩하려는 경우 CollectionViewSource를 사용하지만 이러한 컬렉션을 그룹에 표시하고 목록 컨트롤과 독립적으로 현재 항목을 유지하려고 합니다. 이는 여러 컨트롤을 동일한 컬렉션에 바인딩하고 한 컨트롤의 현재 항목이 다른 바인딩된 컨트롤의 현재 항목을 변경하려는 경우에 특히 유용합니다. 일반적으로 CollectionViewSource를 XAML 리소스로 정의하고 {StaticResource} 태그 확장을 사용하여 바인딩합니다. 그런 다음 코드 숨김의 Source 속성을 지원되는 컬렉션 형식으로 설정할 수 있습니다.

동일한 CollectionViewSource에 바인딩하는 모든 컨트롤에는 항상 동일한 현재 항목이 있습니다. CollectionViewSource.View 속성 값의 ICollectionView.CurrentItem 속성을 통해 프로그래밍 방식으로 현재 항목에 액세스할 수 있습니다.

컬렉션의 항목이 컬렉션 자체이거나 컬렉션이 포함된 개체인 경우 컬렉션을 더 큰 컬렉션 내의 그룹으로 표시할 수 있습니다. 이렇게 하려면 IsSourceGrouped 속성을 true로 설정합니다. 항목에 컬렉션이 포함되어 있지만 컬렉션 자체가 아닌 경우 ItemsPath 속성도 컬렉션 속성의 이름으로 설정해야 합니다.

참고

Source 속성을 다른 CollectionViewSource instance 설정하는 것은 지원되지 않습니다.

생성자

CollectionViewSource()

CollectionViewSource 클래스의 새 instance 초기화합니다.

속성

Dispatcher

이 개체가 연결된 CoreDispatcher 를 가져옵니다. CoreDispatcher는 코드가 비 UI 스레드에서 시작된 경우에도 UI 스레드에서 DependencyObject에 액세스할 수 있는 기능을 나타냅니다.

(다음에서 상속됨 DependencyObject)
IsSourceGrouped

원본 데이터가 그룹화되는지 여부를 나타내는 값을 가져오거나 설정합니다.

IsSourceGroupedProperty

IsSourceGrouped 종속성 속성을 식별합니다.

ItemsPath

CollectionViewSource 내에서 그룹을 찾기 위해 최상위 항목에서 따라야 할 속성 경로를 가져오거나 설정합니다.

ItemsPathProperty

ItemsPath 종속성 속성을 식별합니다.

Source

이 뷰를 만드는 데 사용할 컬렉션 개체를 가져오거나 설정합니다.

SourceProperty

원본 종속성 속성을 식별합니다.

View

CollectionViewSource의 이 instance 현재 연결된 뷰 개체를 가져옵니다.

ViewProperty

View 종속성 속성을 식별합니다.

메서드

ClearValue(DependencyProperty)

종속성 속성의 로컬 값을 지웁니다.

(다음에서 상속됨 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

애니메이션이 활성화되지 않은 경우 적용되는 종속성 속성에 대해 설정된 모든 기본 값을 반환합니다.

(다음에서 상속됨 DependencyObject)
GetValue(DependencyProperty)

DependencyObject에서 종속성 속성의 현재 유효 값을 반환합니다.

(다음에서 상속됨 DependencyObject)
ReadLocalValue(DependencyProperty)

로컬 값이 설정된 경우 종속성 속성의 로컬 값을 반환합니다.

(다음에서 상속됨 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

DependencyObject instance 특정 DependencyProperty의 변경 내용을 수신 대기하기 위한 알림 함수를 등록합니다.

(다음에서 상속됨 DependencyObject)
SetValue(DependencyProperty, Object)

DependencyObject에서 종속성 속성의 로컬 값을 설정합니다.

(다음에서 상속됨 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

RegisterPropertyChangedCallback을 호출하여 이전에 등록된 변경 알림을 취소합니다.

(다음에서 상속됨 DependencyObject)

적용 대상

추가 정보