Skip to content

CollectionChanged not triggering the PropertyDependencies of a Factory.CommandSyncChecked #31

@giuliohome

Description

@giuliohome

Description

I'm trying to detect when an ObservableCollection is not empty and enable a clear command only in that case

Repro steps

I've tried the following

    let clearRecentsCmd = 
        self.Factory.CommandSyncChecked(
            (fun () -> self.ClearRecents()), 
            (fun () -> self.RecentsNotEmpty  ), 
            [ <@@ self.RecentsNotEmpty @@>;  <@@ self.Recents @@>])
    let recents = self.Factory.Backing(<@ self.Recents @>, ObservableCollection<RecentFile>(getRecent())) 
    do
        self.DependencyTracker.AddPropertyDependencies(<@@ self.RecentsNotEmpty @@>, [ <@@ self.Recents @@> ; ])
    member x.Recents with get() = recents.Value and set value = recents.Value <- value
    member x.Add2Recents r = 
        x.Recents.Insert(0,r)
    member x.ClearRecents() =
        x.Recents.Clear()
    member x.RecentsNotEmpty with get() = x.Recents.Count > 0

Expected behavior

x.Recents.Insert(0,r) should raise a Command CanExecuteChanged

Actual behavior

The command doesn't get enabled if I add a new RecentFile to the empty ObservableCollection.

Known workarounds

I'm forced to use the clumsy x.Recents <- ObservableCollection(r :: (x.Recents |> Seq.toList)) instead of x.Recents.Insert(0,r)

Related information

I'm using .Net Framework 4.6.1 and F# 4.4.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions