FuncUI
GitHub Repository
  • Getting Started
  • View Basics
    • Creating views
    • Lifetime
    • Attributes
    • How to create bindings
  • Components
    • Component basics
    • Component lifetime
    • Hooks
  • Common Questions
  • Controls
    • Button
    • Border
    • Calendar
    • CalendarDatePicker
    • CheckBox
    • DatePicker
    • DockPanel
    • Expander
    • ListBox
    • Menu
    • NativeMenu
    • NumericUpDown
    • ProgressBar
    • RadioButton
    • RepeatButton
    • Slider
    • StackPanel
    • Tabs
    • TextBlock
    • TextBox
    • TimePicker
    • ToggleButton
    • ToggleSwitch
Powered by GitBook
On this page
  • Creating views for common controls
  • Creating views for custom controls
  • Passing constructor arguments
  1. View Basics

Creating views

There are multiple ways of creating a view for a certain control. They all have in common that the resulting type is IView or IView<'t>.

Creating views for common controls

FuncUI provides functions for creating standard Avalonia controls. The create function always follows the same pattern.\

internal - signature
module Button =
    val create: attrs: IAttr<'control> list -> IView<'control>
user code
Button.create [
    // view attributes
]

The create function is always found on the module named the same as the Avalonia control.

So the create function for a TextBlock is TextBlock.create, for a StackPanel it's StackPanel.create and so on.

Creating views for custom controls

Even without creating bindings for a control you can create and embed it in a view.

View.createGeneric<MyCustomControl> [
    // view attributes
]

Passing constructor arguments

Sometimes controls don't have a unit constructor and need constructor arguments. Here is how you can pass them.

[
    // view attributes
]
|> View.createGeneric<MyCustomControl> 
|> View.withConstructorArgs [| "constructorArg1" :> obj; "constructorArg2" :> obj |]
    

Last updated 10 months ago