Share via


ItemsControl.ItemsPanel 속성

정의

항목의 레이아웃을 제어하는 패널을 정의하는 템플릿을 가져오거나 설정합니다.

public:
 property System::Windows::Controls::ItemsPanelTemplate ^ ItemsPanel { System::Windows::Controls::ItemsPanelTemplate ^ get(); void set(System::Windows::Controls::ItemsPanelTemplate ^ value); };
[System.ComponentModel.Bindable(false)]
public System.Windows.Controls.ItemsPanelTemplate ItemsPanel { get; set; }
[<System.ComponentModel.Bindable(false)>]
member this.ItemsPanel : System.Windows.Controls.ItemsPanelTemplate with get, set
Public Property ItemsPanel As ItemsPanelTemplate

속성 값

항목 레이아웃에 사용할 패널을 정의하는 ItemsPanelTemplate입니다. ItemsControl 에 대한 기본값은 ItemsPanelTemplate 을 지정하는 StackPanel입니다.

특성

예제

가로 만들려는 ListBox, 가로 지정 하는 템플릿을 만들 수 있습니다 StackPanel 으로 설정 하는 ItemsPanel 속성입니다. 에서는 다음 예제는 ListBoxStyle 만들어지는 가로 ListBox합니다.

<Style TargetType="ListBox">
  <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"/>
      </ItemsPanelTemplate>
    </Setter.Value>
  </Setter>
</Style>

다음 예제에서는 ControlTemplate 가로 만들려면 ListBox 모서리가 둥근입니다. 이 예제에서는 이전 예제와 같이 속성을 설정하는 ItemsPanel 대신 에 가로 StackPanel 가 지정됩니다 ControlTemplate. 속성은 IsItemsHost 에서 StackPaneltrue 설정되며, 이는 생성된 항목이 패널에 있어야 함을 나타냅니다. 이러한 방식으로 지정 하는 경우는 ItemsPanel 를 사용 하지 않고 컨트롤의 사용자가 바꿀 수 없습니다는 ControlTemplate합니다. 따라서 템플릿을 사용하지 않고 패널을 교체하지 않으려는 경우에만 이 작업을 수행합니다.

<Style TargetType="ListBox">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ListBox">
        <Border CornerRadius="5" Background="{TemplateBinding ListBox.Background}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel Orientation="Horizontal"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       IsItemsHost="True"/>
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

또는 동일한 결과 얻으려면 다음을 수행할 수 있습니다. 이 경우에 ItemsPresenter 된 내용에 따라 항목의 레이아웃에 대 한 패널을 만드는 ItemsPanelTemplate합니다.

<Style TargetType="{x:Type ListBox}">
  <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"
                     VerticalAlignment="Center"
                     HorizontalAlignment="Center"/>
      </ItemsPanelTemplate>
    </Setter.Value>
  </Setter>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ListBox}">
        <Border CornerRadius="5"
                Background="{TemplateBinding ListBox.Background}">
          <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <ItemsPresenter/>
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

설명

ListBox경우 기본값 ItemsPanelTemplate 은 를 VirtualizingStackPanel지정합니다. 에 대 한 MenuItem를 사용 하 여 기본 WrapPanel입니다. 에 대 한 StatusBar를 사용 하 여 기본 DockPanel입니다.

ItemsControl항목 레이아웃에 영향을 주려면 이 속성을 사용하여 를 지정합니다 ItemsPanelTemplate.

ItemsControl 시각적 사용자 지정에 뛰어난 유연성을 제공하며 많은 스타일 지정 및 템플릿 속성을 제공합니다. 속성 또는 ItemContainerStyleSelector 속성을 사용하여 ItemContainerStyle 데이터 항목을 포함하는 요소의 모양에 영향을 주는 스타일을 설정합니다. 예를 들어 ListBox, 생성 된 컨테이너는 ListBoxItem 제어;에 대 한 ComboBox, 이들은 ComboBoxItem 컨트롤입니다. 컨트롤에서 그룹화 를 사용하는 경우 또는 GroupStyleSelector 속성을 사용할 GroupStyle 수 있습니다. 데이터 개체의 시각화를 지정하려면 또는 ItemTemplateSelector 속성을 사용합니다ItemTemplate. 자세한 내용은 데이터 템플릿 개요를 참조하세요.

종속성 속성 정보

식별자 필드 ItemsPanelProperty
메타 데이터 속성 설정 true 없음

적용 대상