open System
open Gjallarhorn.Bindable
open Gjallarhorn.Bindable.Framework
open Gjallarhorn.Wpf
open FsXaml
module Program =
type Item = {
Index : int
IsCurrent : bool
}
type Model = {
Items : Item [] ;
CurrentIndex : int
}
let initModel i =
{
Items = Array.init i (fun v ->
{
Index = v
IsCurrent = false
}
)
CurrentIndex = -1
}
type Msg =
| Select of int
let update msg model =
match msg with
| Select ind ->
let items =
model.Items
|> Array.mapi (fun i item ->
{ item with IsCurrent = i = ind }
)
{ Items = items; CurrentIndex = ind }
type ViewModel =
{
Model : Model
Select : VmCmd<Msg>
}
let d = { Model = initModel 1 ; Select = Vm.cmd (Select 0) }
let bindToSource =
Component.create [
<@ d.Model.Items @> |> Bind.oneWay (fun m -> m.Items)
<@ d.Model.CurrentIndex @>
|> Bind.twoWay (fun m -> m.CurrentIndex) Msg.Select
]
let applicationCore =
Framework.application (initModel 5) update bindToSource Nav.empty
type MainWin = XAML<"MainWindow.xaml">
[<STAThread>]
[<EntryPoint>]
let main _ =
Framework.RunApplication (Navigation.singleViewFromWindow MainWin, Program.applicationCore)
1
Expected behaviour:
SelectedItem is highlighten
Current behaviour:
Doesn't seem like any item is selected
MCVE is artificial but the same happens for more complicated cases. And while the code above can be easily rewritten a real code isn't so easy to change.
MCVE
XAML
Expected behaviour:
SelectedItem is highlighten
Current behaviour:
Doesn't seem like any item is selected
MCVE is artificial but the same happens for more complicated cases. And while the code above can be easily rewritten a real code isn't so easy to change.