Skip to content

Conversation

NeilMacMullen
Copy link

@NeilMacMullen NeilMacMullen commented Aug 23, 2025

First off thanks for this amazing library; I'm planning to use it for Kusto-Loco as soon as I get to grips with it :-)

Following through the documentation, my first move was to try to create simple DocumentDock. The documentation suggests this can be easily bound to an Observable Collection and this is indeed the case.. However, if this route is taken there's an unfortunate side-effect that the "+" button on the tab-strip doesn't actually create a new document.

The reason for this is that CreateNewDocument either:

  • attempts to use DocumentFactory to create a new IDockable
  • creates an IDockable from the DocumentTemplate

This PR attempts to make it easier for users to add items from the + button.

Commit 1 in the PR

  • Adds AddDocumentToBoundCollection() to the IFactory interface
  • Modifies the base Factory so that this is a no-op by default
  • Modifies DocumentDock so that it attempts this route before trying the other mechanisms to add a document
  • Adds a test to ensure it is called.

There are a few other approaches that could be taken and might be better..

  • checking for an interface (e.g ICollectionManager) on the DataContext
  • Scanning for an ICommand AddItem property on the DataContext
  • Allow a bindable setter on `DocumentDock.CreateDocument
  • Wrap DocumentDock in a UserControl and override CreateDocument

I'd also be happy to change the naming

Commit 2 in the PR

Adds a working sample using this technique. The document collection is bound to an ObservableCollection and a DockFactory is used to add new documents when '+' is pressed.

Commit 3 in the PR

Some light edits to the documentation to cover a few missing steps I found while trying to follow along. One point of note is that the ViewLocator seems to be redundant if using the ItemCollection approach ?

@NeilMacMullen
Copy link
Author

Hmmm - I'm inclined to abandon this. Although the approach works for a very simple application, features such as float just aren't practical without a code-first approach as far as I can see. Anyway I'll leave it up in case you think bits of it are useful but feel free to close.

@NeilMacMullen
Copy link
Author

NeilMacMullen commented Aug 24, 2025

I came close to gettting this working with floating documents. The main issues were:

-DocumentDock subscribes for changes to the bound collection in the constructor. This means that Initialise is called before Factory is bound and that all initial documents in _generatedDocuments end up with a NULL owner. This means that FindRoot fails when the document is drag outside the initial DocumentDock. It also means Factory.InitLayout is never called so the DefaultWindowLocator is never set.

  • DocumentDock as a null Owner by default so again, FindRoot fails.

If these issues are worked around (I think probably DocumentDock could be refactored to ensures stricter initialisation ordering) then it's possible to drag documents out of the initial DocummentDock into another window.

However, at that point the connection to the original collection is lost so adding/deleting items in the new window doesn't have any effect on the viewmodel collection. I think changes to SplitIntoWindow would be required to change this behaviour - maybe there could be some conditional logic in the case that the DocumentDock is bound to a collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant