The function you are trying to handle the click with has to return a unit- in other words, it has to do something, rather than be something.

What I think you might want, is when the button in the second file is clicked, do what is in the "do" clause in the first file (show the window, with the button with an image on it. If that's not right, what do you want to do?)

I would write a function in the second file:

let myFun (args:RoutedEventArgs) =
let win = Window(Title="Button with Content", Width=300.0, Height=300.0, Content=ButtonWithContent.stack)
win.Show();;

And say

btnWithControl.Click.Add(myFun)

By on 3/9/2009 3:50 PM ()

I got an error:

btnWithContent.Click.Add(buttonWithContentClick)

Error 1 Type mismatch. Expecting a RoutedEventArgs -> unit but given a RoutedEventArgs -> unit -> unit. The type 'unit' does not match the type 'unit -> unit'.

By on 3/10/2009 5:36 AM ()

Hmmmm. What does buttonWithContentClick look like? I'm not getting that with

let myFun (args:RoutedEventArgs) =
let win = Window(Title="Button with Content", Width=300.0, Height=300.0, Content=File2.stack1)
win.Show()

val myFun : RoutedEventArgs -> unit

I could get that with something like

let myFun (args:RoutedEventArgs) =
(fun () ->
let win = Window(Title="Button with Content", Width=300.0, Height=300.0, Content=File2.stack1)
win.Show())

val myFun : RoutedEventArgs -> unit -> unit

But that's not going to give the right type, as you can see.

By on 3/11/2009 4:37 PM ()

Let see …

let buttonWithContentClick (args:RoutedEventArgs) =

(fun () ->

let win = Window(Title="Button with Content",

Width=300.0, Height=300.0, Content=stack1)

win.Show())

val buttonWithContentClick : RoutedEventArgs -> unit -> unit

OK.

let stack =

let temp = StackPanel(Margin=margin1)

let btnWithContent = Button(Margin=margin1,

Content="Button with Content")

temp.Children.Add(btnWithContent) |> ignore

btnWithContent.Click.Add(buttonWithContentClick)

temp

Type mismatch. Expecting a

RoutedEventArgs -> unit

but given a

RoutedEventArgs -> unit -> unit.

The type 'unit' does not match the type 'unit -> unit'.

Wrong. The argument (args:RoutedEventArgs) has no value.

By on 3/13/2009 5:22 AM ()

I think my last post was not clear- you want

let buttonWithContentClick (args:RoutedEventArgs) = <?XML:NAMESPACE PREFIX = O />

let win = Window(Title="Button with Content",

Width=300.0, Height=300.0, Content=stack1)

win.Show()

This will give you the correct type to pass to Add. If that still gives you an error, then there's more in your code than I've seen; I've tested this and it works fine.

I'm not sure what "(args:RoutedEventArgs) has no value" means exactly. When the button is clicked, there will definitely be a RoutedEventArgs object that can be accessed inside the function by the name args. We don't care about it in this case, but it's there, and we need to pass it, or Add won't let us associate the function with the Click event.

By on 3/13/2009 8:02 AM ()

Oops! I made a mistake...

let buttonWithContentClick (args:RoutedEventArgs) =

let win = Window(Title="Button with Content",

Width=300.0, Height=300.0, Content=stack1)

win.Show // ERROR missing ()

Thank-you!!!

By on 3/13/2009 4:23 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper