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

속성 값

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의 StringFormat 속성을 MultiBinding 사용하여 각 항목을 ListBox포함하는 Description Price 문자열을 빌드합니다.

<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 자식 바인딩에 설정된 경우 해당 값이 사용됩니다. 적용 StringFormatStringFormat 자식 바인딩에서 설정되지 않은 경우 해당 바인딩이 설정되면 해당 바인딩이 PriorityBinding 적용됩니다.

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

적용 대상