Browse Source

Add shorthand property AddClassHandler.

pull/83/head
Steven Kirk 11 years ago
parent
commit
f08220c599
  1. 18
      src/Perspex.Base/PerspexObjectExtensions.cs
  2. 7
      src/Perspex.Controls/Window.cs

18
src/Perspex.Base/PerspexObjectExtensions.cs

@ -14,6 +14,24 @@ namespace Perspex
/// </summary> /// </summary>
public static class PerspexObjectExtensions public static class PerspexObjectExtensions
{ {
/// <summary>
/// Subscribes to a property changed notifications for changes that originate from a
/// <typeparamref name="TTarget"/>.
/// </summary>
/// <typeparam name="TTarget">The type of the property change sender.</typeparam>
/// <param name="observable">The property changed observable.</param>
/// <param name="action">
/// The method to call. The parameters are the sender and the event args.
/// </param>
/// <returns>A disposable that can be used to terminate the subscription.</returns>
public static IDisposable AddClassHandler<TTarget>(
this IObservable<PerspexPropertyChangedEventArgs> observable,
Action<TTarget, PerspexPropertyChangedEventArgs> action)
where TTarget : PerspexObject
{
return observable.Subscribe(e => action((TTarget)e.Sender, e));
}
/// <summary> /// <summary>
/// Subscribes to a property changed notifications for changes that originate from a /// Subscribes to a property changed notifications for changes that originate from a
/// <typeparamref name="TTarget"/>. /// <typeparamref name="TTarget"/>.

7
src/Perspex.Controls/Window.cs

@ -66,7 +66,7 @@ namespace Perspex.Controls
static Window() static Window()
{ {
BackgroundProperty.OverrideDefaultValue(typeof(Window), Brushes.White); BackgroundProperty.OverrideDefaultValue(typeof(Window), Brushes.White);
TitleProperty.Changed.AddClassHandler<Window>(x => x.TitleChanged); TitleProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl.SetTitle((string)e.NewValue));
} }
/// <summary> /// <summary>
@ -235,10 +235,5 @@ namespace Perspex.Controls
base.HandleResized(clientSize); base.HandleResized(clientSize);
} }
private void TitleChanged(PerspexPropertyChangedEventArgs e)
{
this.PlatformImpl.SetTitle((string)e.NewValue);
}
} }
} }

Loading…
Cancel
Save