elmish / Elmish.WPF

Static WPF views for elmish programs
Other
421 stars 68 forks source link

How to get the listviewitem when clicking on its checkbox with Binding.twoWay in subModelSeq? #608

Closed awaynemd closed 3 weeks ago

awaynemd commented 4 weeks ago

In the below code, I have a checkbox in the datatemplate of listview items. The checkbox is bound to "fPrint". I can select the listviewitem proper with "SelectedNewPrescription".

The problem I have is that I would like clicking on the checkbox to set the FPrint property on its listviewitem, but selecting the listviewitem should not set the FPrint property. (That is I can't bind the checkbox to the IsSelected event of the listviewitem in the xaml).

Looking at the specs on Binding.twoWay in the Submodelseq, I get the impression that the "click" and the item on which the click occurs is available to the setter--but I am unable to access it with SetFPrint.

Suggestions?

Thanks for any help.

"NewPrescriptions" |> Binding.subModelSeq( (fun m -> m.NewPrescriptions), (fun e -> e.rid), (fun () -> [ "Medname" |> Binding.oneWay (fun (,e) -> e.Medname) "Sig" |> Binding.oneWay (fun (,e) -> e.Sig) "Disp" |> Binding.oneWay (fun (,e) -> e.Disp) "Form" |> Binding.oneWay (fun (,e) -> e.Form) "Refills" |> Binding.oneWay (fun (,e) -> e.Refills) "fPrint" |> Binding.twoWay ((fun (,e:Rx) -> e.fprint), SetFPrint ) ]) ) "SelectedNewPrescription" |> Binding.subModelSelectedItem("NewPrescriptions", (fun m -> m.SelectedNewPrescription), SelectedNewPrescriptionMsg)

awaynemd commented 3 weeks ago

After many hours of research, I find this question can easily be solved by using the CORRECT Binding.subModelSeq override.

Sleep really does help.