Created
October 20, 2012 20:29
-
-
Save thefringeninja/3924680 to your computer and use it in GitHub Desktop.
Double Click with Reactive UI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MyUserControlView() | |
{ | |
InitializeComponent(); | |
var mouseUp = Observable.FromEventPattern< | |
MouseButtonEventHandler, | |
MouseButtonEventArgs> | |
(h => MouseLeftButtonUp += h, h => MouseLeftButtonUp -= h); | |
var doubleClick = mouseUp.SelectMany( | |
e => mouseUp.Take(1).Timeout( | |
TimeSpan.FromMilliseconds(500), | |
Observable.Empty<EventPattern<MouseButtonEventArgs>>())); | |
doubleClick.Select(_ => this.list.SelectedItem) | |
.Where(x => x != null) | |
.Subscribe(x => ((MyViewModel) DataContext).MyCommand.Execute(null)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment