Skip to content

Instantly share code, notes, and snippets.

@emoacht
Last active August 29, 2015 14:11
ScrollViewerSelectorBehavior
public class ScrollViewerSelectorBehavior : DependencyObject, IBehavior
{
public DependencyObject AssociatedObject { get; private set; }
private ScrollViewer AssociatedViewer
{
get { return (ScrollViewer)this.AssociatedObject; }
}
private Selector AssociatedSelector
{
get { return _associatedSelector ?? (_associatedSelector = this.AssociatedObject.GetFirstDescendantOfType<Selector>()); }
}
private Selector _associatedSelector;
private CompositeDisposable disposer;
public void Attach(DependencyObject associatedObject)
{
this.AssociatedObject = associatedObject as ScrollViewer;
if (this.AssociatedObject == null)
{
Debug.WriteLine("Associated object is not ScrollViewer!");
return;
}
AssociatedViewer.Loaded += OnLoaded;
disposer = new CompositeDisposable();
}
public void Detach()
{
if (this.AssociatedObject == null)
return;
AssociatedViewer.Loaded -= OnLoaded;
disposer.Dispose();
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment