question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I had a go at hacking a style DSL. It seems to work. I’m sure you could pick it apart but maybe it’s a start for some ideas. XAML really should die!!

module Control =
    open Avalonia.Styling
    open Avalonia.Controls
    open FSharpx
    let styling stylesList = 
        let styles = Styles()
        for style in stylesList do
            styles.Add style
        Control.styles styles


    let style (selector:Selector->Selector) (setters:IAttr<'a> seq) =
        let s = Style(fun x -> selector x )
        for attr in setters do
            match attr.Property with
            | Some p -> 
                match p.accessor with
                | InstanceProperty x -> failwith "Can't support instance property" 
                | AvaloniaProperty x -> s.Setters.Add(Setter(x,p.value))
            | None -> ()
        s

and then in my view

  let private binFileTemplate (indexedBinFile: IndexedBinFile) (binFileViewer:BinFile->unit) (dispatch: Msg -> unit) =
        let (id, binFile) = indexedBinFile
        let foreground = 
            match binFile.eq_status with
            | DEGREE_EQUAL                                             -> "green" 
            | DEGREE_DIFFERENT                                         -> "red"
            | DEGREE_EXCEPTION_0|DEGREE_EXCEPTION_1|DEGREE_EXCEPTION_2 -> "yellow"
            | DEGREE_SIMILAR|DEGREE_EQUAL_IN_TOLERANCE                 -> "darkgreen"
            | _                                                        -> "brightred"

        (* create row for name, eq_status, deviation *)
        StackPanel.create [
            StackPanel.orientation Orientation.Horizontal
            StackPanel.background "black"
            StackPanel.onDoubleTapped (fun _ -> ViewBinFile(binFileViewer, binFile) |> dispatch )
            let style = [
                TextBlock.width columnWidth
                TextBlock.foreground foreground
                TextBlock.horizontalAlignment HorizontalAlignment.Left
            ]
            StackPanel.children [
                TextBlock.createFromSeq <| seq {
                    yield TextBlock.text binFile.name
                    yield! style
                } 
                TextBlock.createFromSeq <| seq {
                    TextBlock.text (binFile.eq_status |> DU.toString )
                    yield! style
                }
                TextBlock.createFromSeq <| seq {
                    TextBlock.text (binFile.deviation |> sprintf "%g") 
                    yield! style
                }
            ] 
        ]

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
JaggerJocommented, Mar 18, 2020

Yeah, I should do that (and maybe add it to the Wiki - not just because I don’t have a blog 😃). It’s actually not that complicated (or at least I try to keep things simple).

1reaction
bradphelancommented, Mar 18, 2020

Another (maybe) bug with style diffing. If I add duplicate properties to a textblock then I would assume that the last one wins. ie

TextBlock.create [
    TextBlock.width 100.0
    TextBlock.width 200.0
]

However I’ve seen, at least in the context of my datatemplate that it seems to randomly pick between the two. This is important when using yield! to do styling. My code looked like

                TextBlock.create [
                    yield! style
                    TextBlock.text binFile.name
                    ToolTip.tip binFile.name
                    TextBlock.width columnWidth
                ] 

with the defaults in style and overrides in the array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are Domain-Specific Languages (DSL)
A Domain Specific Language is a programming language with a higher level of abstraction optimized for a specific class of problems. A DSL...
Read more >
Domain-specific language
A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language ...
Read more >
Coding Styles: Imperative, Declarative and DSL🤯
DSL stands for Domain Specific Language. It represents that extremity when a language can fit only one domain. Yeah react too has a...
Read more >
dsl/docs/language-reference.md at master · structurizr/dsl
The Structurizr CLI will provide some default views and styles when they are not specified in your DSL - see Convention over configuration,...
Read more >
DSL Guide - Martin Fowler
These tools take an old style of development - which I call language oriented programming and use IDE tooling in a bid to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found