1

I have a strange error with fsxaml and F#. I have a view model and I want to make a call to CommandSync from the factory property but it's not available. Actually it's empty, no functions available. What am I missing here?

code :

namespace ViewModels

open ViewModule


type MainViewModel() as this =
    inherit ViewModelBase()

    let launch() = this.Factory.CommandSync(fun _ -> ())

    member this.LaunchBtn = launch()

P.S I have the ViewModule reference already

FoggyFinder
  • 2,230
  • 2
  • 20
  • 34
Mike F
  • 316
  • 3
  • 14
  • I don't know much about WPF, but from a quick Google search I conclude that you're supposed to write your own ViewModelBase class, not just use one that the framework provides. Is that correct? If so, then showing us the source code for your ViewModelBase class would probably be a good idea: something in there might be the reason why the Factory property is empty. – rmunn Aug 03 '18 at 11:54
  • @rmunn with f# and wpf I always install a reference called ViewModule that gives you the ViewModelBase class to work with. I've never had a problem with that before until now. – Mike F Aug 03 '18 at 12:10
  • I assume https://github.com/fsprojects/FSharp.ViewModule/ the ViewModule you're using? If so, I might have an idea what's wrong. I'll write up an answer, one sec. – rmunn Aug 03 '18 at 12:32

1 Answers1

2

In the ViewModule source in the Factory.fs file, there's a comment:

The F# API is implemented with members having the following signatures via extension methods in the ViewModule.FSharp namespace:

and CommandSync is listed among those extension methods. Since they're extension methods, they won't be available until the ViewModule.FSharp namespace is opened. You've opened the ViewModule namespace, but you may also need to add:

open ViewModule.FSharp

to your code. Once you do that, I think the CommandSync methods (and all the other methods on the Factory property) should become available to you.

rmunn
  • 34,942
  • 10
  • 74
  • 105