예제 #1
0
 /// <summary>
 /// Gets a subject for a <see cref="AvaloniaProperty"/>.
 /// </summary>
 /// <typeparam name="T">The property type.</typeparam>
 /// <param name="o">The object.</param>
 /// <param name="property">The property.</param>
 /// <param name="priority">
 /// The priority with which binding values are written to the object.
 /// </param>
 /// <returns>
 /// An <see cref="ISubject{T}"/> which can be used for two-way binding to/from the
 /// property.
 /// </returns>
 public static ISubject <BindingValue <T> > GetBindingSubject <T>(
     this IAvaloniaObject o,
     AvaloniaProperty <T> property,
     BindingPriority priority = BindingPriority.LocalValue)
 {
     return(Subject.Create <BindingValue <T> >(
                Observer.Create <BindingValue <T> >(x =>
     {
         if (x.HasValue)
         {
             o.SetValue(property, x.Value, priority);
         }
     }),
                o.GetBindingObservable(property)));
 }