다음을 통해 공유


BindingBase.StringFormat 속성

정의

바인딩된 값을 문자열로 표시하는 경우 바인딩의 서식을 지정하는 방법을 지정하는 문자열을 가져오거나 설정합니다.

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

속성 값

바인딩된 값을 문자열로 표시하는 경우 바인딩의 서식을 지정하는 방법을 지정하는 문자열입니다.

예제

다음 예제에서는 속성을 사용하여 StringFormat 통화를 나타내는 문자열로 변환PriceDouble합니다.

<ListView ItemsSource="{StaticResource MyData}">
  <ListView.View>
    <GridView>
      <GridViewColumn DisplayMemberBinding="{Binding Path=Description}"/>
      <GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat=Now {0:c}!}"/>
    </GridView>
  </ListView.View>
</ListView>

다음 예제에서는 a의 StringFormatMultiBinding 속성을 사용하여 각 항목을 ListBox포함하는 DescriptionPrice 문자열을 작성합니다.

<ListBox ItemsSource="{StaticResource MyData}">

  <ListBox.ItemTemplate>
    <DataTemplate>
      <TextBlock>
        <TextBlock.Text>
          <MultiBinding  StringFormat="{}{0} -- Now only {1:C}!">
            <Binding Path="Description"/>
            <Binding Path="Price"/>
          </MultiBinding>
        </TextBlock.Text>
      </TextBlock>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

설명

StringFormat 는 미리 정의된, 복합 또는 사용자 지정 문자열 형식일 수 있습니다. 문자열 형식에 대한 자세한 내용은 형식 서식을 참조하세요.

StringFormat 속성을 설정 Converter 하면 변환기가 먼저 데이터 값에 적용된 다음 StringFormat 적용됩니다.

StringFormat 복합 문자열 형식으로 Binding 설정하면 매개 변수를 하나만 지정할 수 있습니다.

사용 MultiBinding하는 경우 속성에 StringFormat 설정 MultiBinding된 경우에 적용 됩니다. 자식 Binding 개체에 설정된 값 StringFormat 은 무시됩니다. 복합 문자열 형식의 매개 변수 수는 .의 자식 Binding 개체 MultiBinding수를 초과할 수 없습니다.

사용할 PriorityBinding경우 자식 바인딩 개체 또는 둘 다에 대해 PriorityBinding설정할 StringFormat 수 있습니다. 적용된 StringFormat 자식 바인딩에 설정된 경우 해당 값이 사용됩니다. 적용 StringFormatPriorityBindingStringFormat 자식 바인딩에서 설정되지 않은 경우 해당 바인딩이 설정된 경우 해당 바인딩이 적용됩니다.

형식 문자열이 문자로 { 시작하는 경우 XAML 파서는 태그 확장에 대해 혼동합니다. 이러한 모호성을 방지하려면 빈 중괄호 집합으로 서식 문자열을 접두사로 묶습니다.

적용 대상