<!-- All boilerplate for now --> <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> </Application.Resources> </Application>
Here's the code behind:
namespace Spirograph open System open System.Windows open System.Windows.Controls module Main = [<STAThread; EntryPoint>] let main _ = // Create the app and the model with the "business logic", then create the // main window and link its Canvas to the model so the model can access it. // The main window is linked to the app in the Run() command in the last line. let app = App() let model = new Model() let mainWindow = new MainWindow(app, model) model.MyCanvas <- (mainWindow.FindName("myCanvas") :?> Canvas) // Make sure the window is on top, and set its size to 2/3 of the dimensions // of the screen. mainWindow.Topmost <- true mainWindow.Height <- (System.Windows.SystemParameters.PrimaryScreenHeight * 0.67) mainWindow.Width <- (System.Windows.SystemParameters.PrimaryScreenWidth * 0.67) app.Run(mainWindow) // Returns application's exit code.
App.xaml is all boilerplate here, mainly to show where application resources, such as icons, graphics, or external files - can be declared. The companion App.xaml.fs pulls together the Model and the MainWindow, sizes the MainWindow to two-thirds of the available screen size, and runs it.
When you build this, remember to make sure that the Build property for each xaml file is set to Resource. Then you can either run through the debugger or compile to an exe file. Note that you cannot run this using the F# interpreter: The FsXaml package and the interpreter are incompatible.
There you have it. I hope you can use this as a starting point for your own applications, and in doing so you can extend your knowlege beyond what is shown here. Any comments and suggestions will be appreciated.