F# Example

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

fsharpexample.png

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.

fsharpexplorer.png

(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)

FasterWPF.SettingsManager.BeginSettings(mainGrid)
                .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)
                .EndSettings()|>ignore

mainGrid.ShowGridLines<-true

//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))
                .EndSettings();
            
 //2. Canvas
let cnvs = new Canvas()
cnvs.Width<-1280.00
cnvs.Height<-1024.00 
cnvs.Initialize FasterWPF.ContainerType.HorizontalPanel |>ignore
cnvs.Background<-System.Windows.Media.Brushes.WhiteSmoke

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
FasterWPF.CommonExt.BeginComposite(ad)
                .AddExisting(0, 0, mainGrid)
                .EndComposite(null)|>ignore

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

[<STAThread>]
(new Application()).Run(window) |> ignore

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

Comments

No comments yet.