4 people like it.
Like the snippet!
Still Mouse Click Event
Detects a mouse down then up event without a move.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
|
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Input
open System.Windows.Media
[<AutoOpen>]
module Mouse =
let clickedOn (control:UIElement) =
let down = control.MouseLeftButtonDown |> Event.map (fun e -> box e, 1)
let up = control.MouseLeftButtonUp |> Event.map (fun e -> box e, -1)
let mouseButton = Event.merge up down
let mouseMove = control.MouseMove |> Event.map (fun e -> box e, 0)
let mouseEvents = Event.merge mouseButton mouseMove
mouseEvents |> Event.scan (fun (_,last) (e,n) ->
if last = 1 && n = -1 then Some(e),n
else None,n
) (None,0)
|> Event.map (fun (e,_) ->
e |> Option.map (fun e -> e :?> MouseButtonEventArgs))
|> Event.choose id
type AppControl() as control =
inherit UserControl(Width = 320.0, Height = 200.0)
let canvas = Canvas(Background = SolidColorBrush Colors.Orange)
let block = TextBlock(Text="Hit Me", FontSize = 20.0)
let mutable clicks = 0
let clicked = Mouse.clickedOn control
do clicked.Add (fun _ ->
clicks <- clicks + 1
block.Text <- "Still Clicks " + clicks.ToString()
)
do canvas.Children.Add(block)
base.Content <- canvas
#if INTERACTIVE
open Microsoft.TryFSharp
App.Dispatch (fun() ->
App.Console.ClearCanvas()
AppControl() |> App.Console.Canvas.Children.Add
App.Console.CanvasPosition <- CanvasPosition.Right
)
#endif
|
namespace System
namespace System.Windows
namespace System.Media
Multiple items
type AutoOpenAttribute =
inherit Attribute
new : unit -> AutoOpenAttribute
new : path:string -> AutoOpenAttribute
member Path : string
Full name: Microsoft.FSharp.Core.AutoOpenAttribute
--------------------
new : unit -> AutoOpenAttribute
new : path:string -> AutoOpenAttribute
val clickedOn : control:'a -> IEvent<'b>
Full name: Script.Mouse.clickedOn
val control : 'a
val down : IEvent<obj * int>
Multiple items
module Event
from Microsoft.FSharp.Control
--------------------
type Event<'T> =
new : unit -> Event<'T>
member Trigger : arg:'T -> unit
member Publish : IEvent<'T>
Full name: Microsoft.FSharp.Control.Event<_>
--------------------
type Event<'Delegate,'Args (requires delegate and 'Delegate :> Delegate)> =
new : unit -> Event<'Delegate,'Args>
member Trigger : sender:obj * args:'Args -> unit
member Publish : IEvent<'Delegate,'Args>
Full name: Microsoft.FSharp.Control.Event<_,_>
--------------------
new : unit -> Event<'T>
--------------------
new : unit -> Event<'Delegate,'Args>
val map : mapping:('T -> 'U) -> sourceEvent:IEvent<'Del,'T> -> IEvent<'U> (requires delegate and 'Del :> Delegate)
Full name: Microsoft.FSharp.Control.Event.map
val e : obj
val box : value:'T -> obj
Full name: Microsoft.FSharp.Core.Operators.box
val up : IEvent<obj * int>
val e : 'a
val mouseButton : IEvent<obj * int>
val merge : event1:IEvent<'Del1,'T> -> event2:IEvent<'Del2,'T> -> IEvent<'T> (requires delegate and 'Del1 :> Delegate and delegate and 'Del2 :> Delegate)
Full name: Microsoft.FSharp.Control.Event.merge
val mouseMove : IEvent<obj * int>
val mouseEvents : IEvent<obj * int>
val scan : collector:('U -> 'T -> 'U) -> state:'U -> sourceEvent:IEvent<'Del,'T> -> IEvent<'U> (requires delegate and 'Del :> Delegate)
Full name: Microsoft.FSharp.Control.Event.scan
val last : int
val n : int
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val e : obj option
module Option
from Microsoft.FSharp.Core
val map : mapping:('T -> 'U) -> option:'T option -> 'U option
Full name: Microsoft.FSharp.Core.Option.map
val choose : chooser:('T -> 'U option) -> sourceEvent:IEvent<'Del,'T> -> IEvent<'U> (requires delegate and 'Del :> Delegate)
Full name: Microsoft.FSharp.Control.Event.choose
val id : x:'T -> 'T
Full name: Microsoft.FSharp.Core.Operators.id
Multiple items
type AppControl =
inherit obj
new : unit -> AppControl
Full name: Script.AppControl
--------------------
new : unit -> AppControl
val control : AppControl
namespace System.Text
module Mouse
from Script
More information