Beispiel #1
0
        internal static BindingInstance Initialize <TSource>(TSource dataContext, string sourcePath, Action <TSource> onValueChanged)
            where TSource : INotifyPropertyChanged
        {
            var answer = new BindingInstance();

            answer._dataContext            = dataContext;
            answer._propertyChangedHandler = (s, e) =>
            {
                System.Diagnostics.Debug.WriteLine("Binding: " + e.PropertyName);
                if (e.PropertyName.Equals(sourcePath))
                {
                    try
                    {
                        onValueChanged(dataContext);
                    }
                    catch
                    {
                        answer.Dispose();
                    }
                }
            };
            dataContext.PropertyChanged += answer._propertyChangedHandler;

            // Invoke right now
            answer._propertyChangedHandler(dataContext, new PropertyChangedEventArgs(sourcePath));

            return(answer);
        }
Beispiel #2
0
 /// <summary>
 /// Right now only supports a single-level path. You need to hold onto the <see cref="BindingInstance"/> for as long as you'd like the binding to last.
 /// </summary>
 /// <param name="dataContext"></param>
 /// <param name="sourcePath"></param>
 /// <param name="onValueChanged"></param>
 public static BindingInstance SetBinding <TSource>(this TSource dataContext, string sourcePath, Action <TSource> onValueChanged)
     where TSource : INotifyPropertyChanged
 {
     return(BindingInstance.Initialize(dataContext, sourcePath, onValueChanged));
 }