WPF binding to two properties

前端 未结 3 1670
耶瑟儿~
耶瑟儿~ 2020-12-15 04:08

I have a WPF control that has a Message property.

I currently have this:

 
            

        
3条回答
  •  时光取名叫无心
    2020-12-15 04:15

    Try use the MultiBinding:

    Describes a collection of Binding objects attached to a single binding target property.

    Example:

    XAML

    
       
           
              
              
           
       
    
    

    Converter

    public class NameConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string name;
    
            switch ((string)parameter)
            {
                case "FormatLastFirst":
                    name = values[1] + ", " + values[0];
                    break;
                case "FormatNormal":
                    default:
                    name = values[0] + " " + values[1];
                    break;
            }
    
            return name;
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            string[] splitValues = ((string)value).Split(' ');
            return splitValues;
        }
    }
    

提交回复
热议问题