GroupStyle.HeaderStringFormat 속성

정의

헤더가 문자열로 표시되는 경우 헤더의 형식을 지정하는 방법을 지정하는 합성 문자열을 가져오거나 설정합니다.Gets or sets a composite string that specifies how to format the header if it is displayed as a string.

public:
 property System::String ^ HeaderStringFormat { System::String ^ get(); void set(System::String ^ value); };
public string HeaderStringFormat { get; set; }
member this.HeaderStringFormat : string with get, set
Public Property HeaderStringFormat As String

속성 값

헤더가 문자열로 표시되는 경우 이 헤더의 형식을 지정하는 방법을 지정하는 합성 문자열입니다.A composite string that specifies how to format the header if it is displayed as a string.

예제

다음 예제에서는 ListBox 가격 범위에서 항목의 컬렉션을 그룹화 하는 합니다.The following example creates a ListBox that groups a collection of items by price range. 변환기를 GroupByPrice, 각 항목의 가격을 초과 하는 정수 값을 반환 합니다.The converter, GroupByPrice, returns an integer value that is above each item's price. 예를 들어 항목의 가격은 0과 100 사이의 이면 변환기 100을 반환 합니다.For example, if an item's price is between 0 and 100, the converter returns 100. 예제에서는 HeaderStringFormat 각 가격 범위에 대 한 상한값을 포함 하는 문자열을 만듭니다.The example uses the HeaderStringFormat to create a string that includes the upper limit for each price range. 예를 들어 미국의 주가 100 달러의 항목 "100 달러에서 항목" 이라는 제목 아래에서 그룹화 됩니다.For example, in the United States, items that are under 100 dollars are grouped under a heading that says "Items under $100".

<StackPanel>
  <StackPanel.Resources>

      <src:ItemsForSale x:Key="MyData"/>
      <src:GroupByPrice x:Key="GroupByPrice"/>
  
      <CollectionViewSource x:Key="PriceGroup" Source="{StaticResource MyData}">
      
        <CollectionViewSource.GroupDescriptions>
          <PropertyGroupDescription PropertyName="Price"
                                    Converter="{StaticResource GroupByPrice}"/>
      </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>
  </StackPanel.Resources>
  
  <ListBox ItemsSource="{Binding Source={StaticResource PriceGroup}}"
           DisplayMemberPath="Description">
    <ListBox.GroupStyle>
      <GroupStyle HeaderStringFormat="Items under {0:c}"/>
    </ListBox.GroupStyle>
  </ListBox>
</StackPanel>

다음 예제와 GroupByPrice 클래스를 PurchaseItem 클래스 및 컬렉션은는 ListBox 에 바인딩된 합니다.The following example shows the GroupByPrice class, the PurchaseItem class, and the collection that the ListBox is bound to.

// The converter to group the items.
public class GroupByPrice : IValueConverter
{
    public object Convert(object value,
                          Type targetType,
                          object parameter,
                          System.Globalization.CultureInfo culture)
    {

        if (!(value is double))
        {
            return null;
        }

        double itemPrice = (double)value;

        if (itemPrice < 100)
        {
            return 100;
        }

        if (itemPrice < 250)
        {
            return 250;
        }

        if (itemPrice < 500)
        {
            return 500;
        }

        return 1000;



    }

    public object ConvertBack(object value,
                              Type targetType,
                              object parameter,
                              System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

// The type of objects that are added to the ItemsControl.
public class PurchaseItem 
{
    public string Description { get; set; }
    public double Price { get; set; }
    public DateTime OfferExpires { get; set; }

    public PurchaseItem()
    {
    }

    public PurchaseItem(string desc, double price, DateTime endDate)
    {
        Description = desc;
        Price = price;
        OfferExpires = endDate;
    }

    public override string ToString()
    {
        return String.Format("{0}, {1:c}, {2:D}", Description, Price, OfferExpires);
    }
}

// The source of the ItemsControl.
public class ItemsForSale : ObservableCollection<PurchaseItem>
{

    public ItemsForSale()
    {
        Add((new PurchaseItem("Snowboard and bindings", 120, new DateTime(2009, 1, 1))));
        Add((new PurchaseItem("Inside C#, second edition", 10, new DateTime(2009, 2, 2))));
        Add((new PurchaseItem("Laptop - only 1 year old", 499.99, new DateTime(2009, 2, 28))));
        Add((new PurchaseItem("Set of 6 chairs", 120, new DateTime(2009, 2, 28))));
        Add((new PurchaseItem("My DVD Collection", 15, new DateTime(2009, 1, 1))));
        Add((new PurchaseItem("TV Drama Series", 39.985, new DateTime(2009, 1, 1))));
        Add((new PurchaseItem("Squash racket", 60, new DateTime(2009, 2, 28))));

    }

}
' The converter to group the items.
Public Class GroupByPrice
    Implements IValueConverter
    Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert

        If Not(TypeOf value Is Double) Then
            Return Nothing
        End If

        Dim itemPrice As Double = CDbl(value)

        If itemPrice < 100 Then
            Return 100
        End If

        If itemPrice < 250 Then
            Return 250
        End If

        If itemPrice < 500 Then
            Return 500
        End If

        Return 1000



    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class

' The type of objects that are added to the ItemsControl.
Public Class PurchaseItem
    Public Property Description() As String
    Public Property Price() As Double
    Public Property OfferExpires() As Date

    Public Sub New()
    End Sub

    Public Sub New(ByVal desc As String, ByVal price As Double, ByVal endDate As Date)
        Description = desc
        Me.Price = price
        OfferExpires = endDate
    End Sub

    Public Overrides Function ToString() As String
        Return String.Format("{0}, {1:c}, {2:D}", Description, Price, OfferExpires)
    End Function
End Class

' The source of the ItemsControl.
Public Class ItemsForSale
    Inherits ObservableCollection(Of PurchaseItem)

    Public Sub New()
        Add((New PurchaseItem("Snowboard and bindings", 120, New Date(2009, 1, 1))))
        Add((New PurchaseItem("Inside VB, second edition", 10, New Date(2009, 2, 2))))
        Add((New PurchaseItem("Laptop - only 1 year old", 499.99, New Date(2009, 2, 28))))
        Add((New PurchaseItem("Set of 6 chairs", 120, New Date(2009, 2, 28))))
        Add((New PurchaseItem("My DVD Collection", 15, New Date(2009, 1, 1))))
        Add((New PurchaseItem("TV Drama Series", 39.985, New Date(2009, 1, 1))))
        Add((New PurchaseItem("Squash racket", 60, New Date(2009, 2, 28))))

    End Sub

End Class

설명

HeaderStringFormat 미리 정의 된, 복합 또는 사용자 지정 문자열 형식의 수 있습니다.HeaderStringFormat can be a predefined, composite, or custom string format. 문자열 형식에 대 한 자세한 내용은 참조 하세요. 형식합니다.For more information about string formats, see Formatting Types. 설정 하는 경우는 HeaderTemplate 또는 HeaderTemplateSelector 의 속성을 GroupStyleHeaderStringFormat 속성은 무시 됩니다.If you set the HeaderTemplate or HeaderTemplateSelector property of a GroupStyle, the HeaderStringFormat property is ignored.

적용 대상