2014-06-09 2 views
15
내가 바인더 제본 데이터와 함께 텍스트를 표시하기 위해 노력하고

, 예를 들어, 나는 코드가 있습니다윈도우 폰 8.1 XAML있는 StringFormat

<TextBlock Text="{Binding Shorthand}" Style="{ThemeResource ListViewItemTextBlockStyle}" /> 

내가 '속기'이전에 텍스트를 추가하려면, 내가 가진 것과을 그러나 문제는이 8.1에서 일을 할 수있는 방법은 더 이상, 제대로 작동하지 않습니다

<TextBlock Text="{Binding Path=Shorthand, StringFormat={0} text I want to add}" Style="{ThemeResource ListViewItemTextBlockStyle}" /> 

:이의 라인을 따라 바인딩, 뭔가의 속성으로있는 StringFormat을 사용하여 가능한 것 읽기?

+0

"작동하지 않는 것 같아요"는 진단 적이지 않습니다. –

+0

'StringFormat ='{0} '텍스트에'missing '을 추가하지 않으셨습니까? –

+1

오류 : "StringFormat '속성이'바인딩 '유형에서 발견되지 않았습니다." – blawford

답변

30

StringFormat은 WinRT에서 지원되지 않습니다. 당신의 바인딩에서 그것을

<Page.Resources> 
    <local:StringFormatConverter x:Name="StringFormat"/> 
</Page.Resources> 

를 사용 : 당신의 페이지 자원 선언 다음

public class StringFormatConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, string language) 
    { 
     return string.Format(parameter as string, value); 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, string language) 
    { 
     return null; 
    } 
} 

:

<TextBlock Text="{Binding Path=SomeText, Converter={StaticResource ResourceKey=StringFormat}, ConverterParameter='Hello {0}'}" /> 
16

처럼을하지만, 쉽게 사용자 정의 변환을 작성하여 교체 할 수 있습니다 @KooKiz는 현재 StringFormat이 지원되지 않는다고 지적했지만, 변환기를 사용하지 않고 인라인 실행으로 라인을 분리하는 것과 동일한 효과를 얻을 수 있습니다.

<TextBlock> 
    <Run Text="Hey I wanted to put this text in front of "/> 
    <Run Text="{Binding Path=Shorthand}"/> 
    <Run Text=" and I also wanted some text after it. Neato.."/> 
</TextBlock> 

호프가 도움이 되었으면 좋겠다. https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.data.ivalueconverter

그것은 잘 작동 :

0

나는 (마이크로 소프트 지음)이 방법을 사용!

관련 문제