Is it possible to add more characters after a binding in xaml?

后端 未结 7 1054
小蘑菇
小蘑菇 2021-02-02 10:36

I was wondering something, and couldn\'t find any relevant topics. I have following binding :

Content=\"{x:Static resx:Resource.Form_OtherOption_Description}\"
<         


        
7条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 11:27

    You can create a converter that takes the input string and adds the ":".

    public class AddStringToStringConverter : IValueConverter
    {
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string input = value as string;
            string suffix = parameter as string;
    
            return input + suffix;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    Xaml:

    
        
    
    ...
    

    Or something like that. Tried it and it worked for my source at least.

    If you have whitespace and the like in you ConverterParameter you can use signle quotes to make sure it does not get disposed.

    Edit: Oh right... yeah... there's also StringFormat which i have never needed before, ehehehe...

提交回复
热议问题