This project is read-only.
F# Example

NOTE: this example has not been updated with the Version 5.0.0 improvements.


This is a basic 'Hello World' example coded in F#. If you click on the 'Hello World' label, it will launch a simple OK dialogbox.

Here is an example of the references. Also, note that the PresentationFramework.Aero.dll from Downloads should be added to the solution with Build Action: Content and Copy To Output Directory: Copy Always so that it may be found.


(Note: you may likely have to set your target platform in your solution to x86 since I built the dll's to this . . .)

And here is the code . . . if time permits, I may provide a more full-featured demo eventually since the concise nature of F# may dovetail nicely with WPF Composites (WPF-CPS):

open System
open System.Xaml
open System.Windows
open System.Dynamic
open System.Windows.Controls
open System.Windows.Documents
open System.Windows.Input
open System.Windows.Media  
open System.Windows.Shapes
open FasterWPF
open System.Linq

let window = new Window()
//4. Grid
let mainGrid = new Grid()
let g = FasterWPF.GridExt.Initialize(mainGrid,1280.00, 1024.00 , 23.0, ContainerType.VerticalPanel, 4, 3, 1.0, GridUnitType.Star, 1.0, GridUnitType.Star, 100.0, GridUnitType.Pixel)

                .SetItemBorderSettings(System.Double.NaN, System.Double.NaN, Brushes.Silver, new Thickness(1.0))
                .SetFontOnLabel(0, 0, "Segoe UI", 20.0, FontWeights.Bold, FontStyles.Normal)
                .Set<TextBox, Grid>(1, 1,"Text", "Hi there!")
                .Set<TextBox, Grid>("HorizontalAlignment", System.Windows.HorizontalAlignment.Stretch)
                .Set<DatePicker, Grid>("HorizontalAlignment", System.Windows.HorizontalAlignment.Stretch)
                .Set<Button, Grid>("Height", 50.0)
                .Set<Label, Grid>("Padding", new Thickness(5.0, 25.0, 5.0, 5.0))
                .SetHorizontalAlignmentForLabel(0, 0, System.Windows.HorizontalAlignment.Center)


//1. Window
let z = window.Initialize FasterWPF.ContainerType.DockPanel  |>ignore
FasterWPF.SettingsManager.SetCompositeDockPanelLastChildFill<Window>(window, true) |>ignore

let x = FasterWPF.SettingsManager.BeginSettings(window)
                .SetItemBorderSettings(System.Double.NaN, System.Double.NaN, Brushes.Silver, new Thickness(5.0))
 //2. Canvas
let cnvs = new Canvas()
cnvs.Initialize FasterWPF.ContainerType.HorizontalPanel |>ignore

let y = FasterWPF.CommonExt.BeginComposite(window)
           .AddExisting(0, 0, cnvs)
           .EndComposite(null) |>ignore

//3. Adorner Decorator
let ad = new AdornerDecorator()
let a = ad.Initialize(1280.00, 1024.00 , ContainerType.ContentControlPanel) |>ignore
                .AddExisting(0, 0, mainGrid)

let cnvsguidAdorner = Guid.NewGuid().ToString()
let dialogGuid = Guid.NewGuid().ToString()

let c = FasterWPF.CommonExt.BeginComposite(cnvs, cnvsguidAdorner).AddExisting(0, 0, ad).EndComposite(new CanvasArgs(new Nullable<float>(0.0), new Nullable<float>(0.0), new Nullable<int>(1)))
let clickEventHandler = new MouseButtonEventHandler(fun (o: Object)(ev: MouseButtonEventArgs) ->
                FasterWPF.ContemporaryStyle.ShowOKDialog(cnvs, dialogGuid, "  Clicked 'Hello World'.", 200.0, 505.0, 405.0, Brushes.Black, new Thickness(1.0), Brushes.WhiteSmoke, Brushes.White, Brushes.Gray, Brushes.Black, Brushes.LightGray)|>ignore)
let helloWorldLabel = FasterWPF.CommonExt.BeginComposite(mainGrid).AddLabel(0, 0, "Hello World", Brushes.DarkBlue, Brushes.White).SubscribeEventOnChild<Label, Grid>(0, 0, "PreviewMouseDown", clickEventHandler).EndComposite<Grid, GridArgs>(new GridArgs(0,0)) 

let ccp = CommonExt.GetContainerFromComposite<StackPanel, Grid>(mainGrid, helloWorldLabel)
ccp.Background<- Brushes.Gold;

FasterWPF.CommonExt.BeginComposite(mainGrid).AddLabel(1, 0, "First Name", Brushes.DarkBlue, Brushes.White)
                   .AddAnything<TextBox, Grid>(1, 1)
                   .AddAnything<Rectangle, Grid>(2, 2)
                   .AddLabel(1, 3, "Last Name", Brushes.DarkBlue, Brushes.White)
                   .AddAnything<TextBox, Grid>(1, 4)
                   .AddAnything<Rectangle, Grid>(2, 5)
                   .AddLabel(1, 6, "Date", Brushes.DarkBlue, Brushes.White)
                   .AddAnything<DatePicker, Grid>(1, 7)
                   .AddAnything<Rectangle, Grid>(2, 8)
                   .EndComposite(new GridArgs(1, 0))|>ignore

(new Application()).Run(window) |> ignore

Last edited Mar 11, 2014 at 5:56 AM by stagathome0069, version 11


No comments yet.