Windows Phone 8.1 XAML StringFormat

后端 未结 3 1994
迷失自我
迷失自我 2020-12-15 07:27

I am trying to display some text along with binded data, for example, I have the code:



        
3条回答
  •  执念已碎
    2020-12-15 08:10

    StringFormat isn't supported on WinRT. However, you can easily replace it by creating a custom converter:

    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;
        }
    }
    

    Then declare it in your page resources:

    
        
    
    

    And use it in your bindings:

    
    

提交回复
热议问题