elmish / Elmish.WPF

Static WPF views for elmish programs
Other
429 stars 71 forks source link

[Samples] from dynamic bindings to static VM ("SubModelOpt" sample) #607

Closed YkTru closed 3 months ago

YkTru commented 3 months ago

be replaced by:
let form2Visible_Binding =
    Binding.oneWay (fun (m: App.Model) ->
        match m.Dialog with
        | Some (App.Dialog.Form2 _) -> true
        | _ -> false)
and same for all other binding helpers?

---

- Problem: `DataContext="{Binding Form1}"` (and Form2) is the only binding unable to resolve at compile time (though at runtime it works fine):
```fs
<local:Form1
    d:DataContext="{Binding DataContext.Form1, RelativeSource={RelativeSource AncestorType=StackPanel}}"
    DataContext="{Binding Form1}"
    Visibility="{Binding DataContext.Form1Visible, RelativeSource={RelativeSource AncestorType=StackPanel}, Converter={StaticResource VisibilityConverter}}" />

codelens says: (Form1_ViewModel).Path=, is there a way to access (App_ViewModel).Path= here?

YkTru commented 3 months ago

@marner2 ?

YkTru commented 3 months ago

@TysonMN ? (sorry to tag you but I don't know who to ask else)

marner2 commented 3 months ago

I think you're on to something here, but we don't want to replace the old versions yet. This all looks like a correct transform though at my first go through. I'll have to download the source to see what's going on with that binding issue. My guess is that it's something to do with that d:DataContext being different from the DataContext.

TysonMN commented 3 months ago

Sounds like you are doing too much in one PR. If you want to change from 2 to 4 spaces for intention, then do that in a PR of its own.

If you want people to review your work, then make your work easy to review.

YkTru commented 3 months ago

@marner2 Great, when you say :

I think you're on to something here

1-Which part exactly do you think should be kept/revised/removed?

--

My guess is that it's something to do with that d:DataContext being different from the DataContext.

2-What do you mean "being different" since the code is:

d:DataContext="{Binding DataContext.Form1, RelativeSource={RelativeSource AncestorType=StackPanel}}"
    DataContext="{Binding Form1}"

?

Thank you

YkTru commented 3 months ago

Sounds like you are doing too much in one PR. If you want to change from 2 to 4 spaces for intention, then do that in a PR of its own.

If you want people to review your work, then make your work easy to review.

@TysonMN You're absolutely right, changing the "spaces" add too many changes, would you advise me to make another PR with only the modified code, but keeping the 2-spaces indentation of the original sample? (sorry, I'm new to PR-ing)

TysonMN commented 3 months ago

Yes