0

This is related to this question

MVVM way to close document with possibility to cancel out

I'm using a third party library (AvalonDock) It has a CloseCommand property, how can I hook this property up to a Action method using Caliburn?

with vanilla WPF it could look like this

<ad:DockingManager
    DataContext="{Binding Manager}"
    DocumentsSource="{Binding Documents}">

    <ad:DockingManager.LayoutItemContainerStyle>
        <Style TargetType="{x:Type ad:LayoutItem}">
            <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
        </Style>
    </ad:DockingManager.LayoutItemContainerStyle>

</ad:DockingManager>
Community
  • 1
  • 1
Anders
  • 17,306
  • 10
  • 76
  • 144
  • On what class is the `CloseCommand` property defined, Can you put a link ? – Ibrahim Najjar Oct 10 '13 at 14:06
  • I don't think *(not sure)* it is possible in your situation because the Action mechanism relies on bubbling routed events to fire, and what's wrong with what you are doing currently ? – Ibrahim Najjar Oct 10 '13 at 14:16
  • Well, it works, but I have to wrap the event arg in a callback etc. – Anders Oct 10 '13 at 14:18
  • You could possibly add a `SpecialValues` entry and then handle the original callback in the special values processing callback by inspecting the object type - that way you can abstract away the whole routine (the same way it's done in the link provided) but you don't need to do any processing in your VM – Charleh Oct 11 '13 at 15:35
  • Hmm, do you have any more info @Charleh? – Anders Oct 14 '13 at 08:49
  • `SpecialValues` are the dollar prefixed values in actions e.g. `SomeAction($eventargs)`. You can specify your own by using the `SpecialValues.Add` method which takes a `string`, and an `Action`. This is the callback that will be fired when the special value is parsed. In this callback you can access the whole execution context, and therefore you can do the checks mentioned in the linked question and wrap the values in an `IEnumerable` - then pass this `IEnumerable` as an explicit value to the VM without doing any additional processing in the VM – Charleh Oct 14 '13 at 10:52
  • But the IEnumerable is created in the VM? Its not a argument to the VM . edit: Btw, I'm allready using this approuch in my linked question https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.GUI/Common/AvalonDock/DocumentContext.cs – Anders Oct 14 '13 at 10:53

1 Answers1

1

If i understand you correctly, you can try this.

<ad:DockingManager cal:Message.Attach="[Event DocumentClosed] = [Action DockingManager_DocumentClosed($eventArgs)]" />

In your ViewModel

public void DockingManager_DocumentClosed(DocumentClosedEventArgs e)
        {
            Models.Documents.Document doc = e.Document.Content as Models.Documents.Document;
            DocumentSources.Remove(doc);
        }

You have several options from there.

ps: Models.Documents is a class, where my (document) collections are stored

Insight
  • 196
  • 1
  • 13
  • This does not help me, I allready use the DocumentClosed event if you check the link in my question. I need to use the Command, if I do i can add can cancel the remove from there. – Anders Dec 20 '13 at 12:18
  • @Insight Do you know if there is a way of passing the Document itself as parameter to the method instead of $eventArgs? – Brutus Jan 19 '17 at 09:38