/// <summary> /// Listens to the changed properties and merge the event to a sequence. /// </summary> /// <typeparam name="TModel">The type of the source model.</typeparam> /// <typeparam name="TValue">The type of the source value.</typeparam> /// <param name="source">The source model.</param> /// <param name="property">The properties expressions.</param> /// <returns>Event sequence</returns> public static ObservableWithModel <TModel> Listen <TModel, TValue>(this TModel source, Expression <Func <TModel, TValue> > property ) where TModel : BindableBase <TModel> { var value = source.GetValueContainer(property).Value; var rval = new ObservableWithModel <TModel>( source, source .GetValueContainer(property) .GetEventObservable() .Select(y => y.EventArgs) .StartWith( new ValueChangedEventArgs <TValue>(property.Name, default(TValue), value))); return(rval); }
/// <summary> /// /// </summary> /// <typeparam name="TModel"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="sourceOb"></param> /// <param name="property"></param> /// <returns></returns> public static ObservableWithModel <TModel, IDictionary <string, ValueChangedEventArgs> > Also <TModel, TValue>(this ObservableWithModel <TModel> sourceOb, Expression <Func <TModel, TValue> > property ) where TModel : BindableBase <TModel> { var source = sourceOb.Model; var value = source.GetValueContainer(property).Value; var seq1 = sourceOb; var seq2 = source .GetValueContainer(property) .GetEventObservable() .Select(y => y.EventArgs) .StartWith( new ValueChangedEventArgs <TValue>(property.Name, default(TValue), value)); var newseq = seq1.Zip( seq2, (i1, i2) => new Dictionary <string, ValueChangedEventArgs>() { { i1.PropertyName, i1 }, { i2.PropertyName, i2 } }); return(new ObservableWithModel <TModel, IDictionary <string, ValueChangedEventArgs> >( source, newseq )); }