Binding the Path Property of a Binding

前端 未结 5 1807
广开言路
广开言路 2020-12-11 09:24

is it possible to bind the Path property of a binding to another property?

I want to realize this code:

Text=\"{Binding Path={Binding Path=CurrentPat         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 09:46

    I think converter can helps your. Expample

    First control

    Text="{Binding Path=CurrentPath}"
    

    Second control

    Text="{Binding Path=CurrentPath, Convertor={converters:MyConvertor}}"
    

    Base converter

    public abstract class ConvertorBase : MarkupExtension, IValueConverter
        where T : class, new()
        {
                public abstract object Convert(object value, Type targetType, object parameter,
                CultureInfo culture);
    
                public virtual object ConvertBack(object value, Type targetType, object parameter,
                CultureInfo culture)
            {
                throw new NotImplementedException();
            }
    
            #region MarkupExtension members
    
            public override object ProvideValue(IServiceProvider serviceProvider)
            {
                if (_converter == null)
                    _converter = new T();
                return _converter;
            }
    
            private static T _converter = null;
    
            #endregion
        }
    

    MyConverter

     public class MyConverter: ConvertorBase
        {
            public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return (string)value.Equals("blabla") ? "Yes" : "No"; // here return necessary parametr
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return null;
            }
        }
    

提交回复
热议问题