Reputation: 680
I have this really simple program to get RSS-feeds from a website and populate a listbox with the items. Whenever the user selects an item and presses Enter, it should go to a web-page. this is the KeyUp event handler!
rssList.KeyUp
|> Event.filter (fun e -> rssList.SelectedItems.Count > 0)
|> Event.filter (fun (args:Input.KeyEventArgs) -> args.Key = Key.Enter)
|> Event.add -> let feed = unbox<RSSFeed> rssList.SelectItem)
Process.Start(feed.Link) |> ignore)
What I'm getting is the following:
Anybody any idea why this is happening? My goal is (you guessed it) just to open 1 browser window and 1 page PER trigger
Upvotes: 2
Views: 194
Reputation: 680
I got it working properly by implementing the Handled property of the event args with the following:
let doubleClick = new MouseButtonEventHandler(fun sender (args:MouseButtonEventArgs) ->
let listBox = unbox<ListBox> sender
match listBox.SelectedItems.Count > 0 with
| true ->
let listBox = unbox<ListBox> sender
let feed = unbox<RSSFeed> listBox.SelectedItem
Process.Start(feed.Link) |> ignore
args.Handled <- true; ()
| false ->
args.Handled <- true; ())
thanks to everyone who helped me here!
Upvotes: -1
Reputation: 40818
There are several compilation errors in your example including a malformed lambda expression, mismatched parentheses, incorrect identitfiers (SelectItem
is not a property, I'm assuming you mean SelectedItem
not SelectedItems
), and incorrect indentation following the let feed
binding.
Below is a simplified example that works as you intended. The selected item in the top ListBox is put into the bottom ListBox when the user hits Enter.
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Input
[<EntryPoint>]
[<STAThread>]
let main argv =
let panel = new DockPanel()
let listBox = new ListBox()
for i in [| 1 .. 10 |] do
listBox.Items.Add i |> ignore
DockPanel.SetDock(listBox, Dock.Top)
let listBox2 = new ListBox(Height = Double.NaN)
panel.Children.Add listBox |> ignore
panel.Children.Add listBox2 |> ignore
listBox.KeyUp
|> Event.filter (fun e -> listBox.SelectedItems.Count > 0)
|> Event.filter (fun e -> e.Key = Key.Enter)
|> Event.add (fun e -> let i = unbox<int> listBox.SelectedItem
listBox2.Items.Add(i) |> ignore)
let win = new Window(Content = panel)
let application = new Application()
application.Run(win) |> ignore
0
Upvotes: 1