diff --git a/samples/Xamarin.Forms/CounterApp/CounterApp/App.fs b/samples/Xamarin.Forms/CounterApp/CounterApp/App.fs index 439f3785..4d871e0d 100644 --- a/samples/Xamarin.Forms/CounterApp/CounterApp/App.fs +++ b/samples/Xamarin.Forms/CounterApp/CounterApp/App.fs @@ -41,6 +41,12 @@ module App = let init () = initModel (), [] + let createStyleFor<'T when 'T :> BindableObject> setters = + let style = Style(typeof<'T>) + for property, value in setters do + style.Setters.Add(Setter(Property = property, Value = value)) + style + let update msg model = match msg with | Increment -> { model with Count = model.Count + model.Step }, [] @@ -57,10 +63,17 @@ module App = Label(string model.Count) .automationId("CountLabel") .centerTextHorizontal() + .style ( + createStyleFor [ Label.TextColorProperty, box Color.Green + Label.FontSizeProperty, box 24. ] + ) Button("Increment", Increment) + .style( + createStyleFor [ Button.BackgroundColorProperty, box Color.Green + Button.TextColorProperty, box Color.White ] + ) .automationId("IncrementButton") - .textColor(Color.Red) Button("Decrement", Decrement) .automationId("DecrementButton") @@ -93,4 +106,4 @@ module App = ) ) - let program = Program.statefulApplicationWithCmdMsg init update view mapCmdMsgToCmd \ No newline at end of file + let program = Program.statefulApplicationWithCmdMsg init update view mapCmdMsgToCmd diff --git a/src/Fabulous.XamarinForms/WidgetExtensions.fs b/src/Fabulous.XamarinForms/WidgetExtensions.fs index 65d381c8..57453b07 100644 --- a/src/Fabulous.XamarinForms/WidgetExtensions.fs +++ b/src/Fabulous.XamarinForms/WidgetExtensions.fs @@ -84,7 +84,11 @@ type AdditionalViewExtensions = [] static member inline centerTextHorizontal(this: Label<_>) = this.AddScalarAttribute(Label.HorizontalTextAlignment.WithValue(TextAlignment.Center)) - + + [] + static member inline style(this: #IViewWidgetBuilder<'msg>, style: Xamarin.Forms.Style) = + this.AddScalarAttribute(NavigableElement.Style.WithValue(style)) + [] static member inline centerTextVertical(this: Label<_>) = this.AddScalarAttribute(Label.VerticalTextAlignment.WithValue(TextAlignment.Center)) diff --git a/src/Fabulous.XamarinForms/Xamarin.Forms.Core.Attributes.fs b/src/Fabulous.XamarinForms/Xamarin.Forms.Core.Attributes.fs index 1b269539..4adf8c8b 100644 --- a/src/Fabulous.XamarinForms/Xamarin.Forms.Core.Attributes.fs +++ b/src/Fabulous.XamarinForms/Xamarin.Forms.Core.Attributes.fs @@ -3,7 +3,6 @@ open Fabulous open Fabulous.XamarinForms open Xamarin.Forms -open System.Collections.Generic module Application = let MainPage = Attributes.defineWidget ViewNode.getViewNode "Application_MainPage" (fun target -> (target :?> Xamarin.Forms.Application).MainPage) (fun target value -> (target :?> Xamarin.Forms.Application).MainPage <- unbox value) @@ -42,6 +41,9 @@ module VisualElement = let Width = Attributes.defineBindable Xamarin.Forms.VisualElement.WidthRequestProperty let IsVisible = Attributes.defineBindable Xamarin.Forms.VisualElement.IsVisibleProperty +module NavigableElement = + let Style = Attributes.defineBindable