Referencing WPF namespaces in F# 4.0 RRS feed

  • Question

  • I am going through several resources to learn F#, including the Pluralsight course, Introduction to F#. I am using VS2015 Enterprise. The code I'm using is:

    open System

    open System.Windows

    open System.Windows.Controls

    let loadWindows() = 

        letresourceLocator = newUri("/HelloWorldWPF;component/MainWindow.xaml", UriKind.Relative)

        letwindow = Application.LoadComponent(resourceLocator) :?> Window

        (window.FindName("clickButton") :?> Button).Click.Add(

            fun_ ->MessageBox.Show("Hello World!") |> ignore)



    (newApplication()).Run(loadWindow()) |> ignore

    I've got a simple XAML page as a resource:





            <ButtonName="clickButton"Content="Click me!"Height="40"Width="150" />



    I'm getting errors that Application, Window and Grid are not defined.  It seems there is a namespace reference issue.  I could only get the "open System.Windows.Controls" to avoid an error after adding a reference to the System.Windows.Controls.Ribbon assembly.

    My question is,  "How does one reliably set .NET namespace references in F#?








    Saturday, April 16, 2016 4:13 PM


  • I got it to work by adding a reference to the PresentationFramework.
    • Marked as answer by Andy ONeill Saturday, April 16, 2016 5:47 PM
    Saturday, April 16, 2016 5:26 PM

All replies