[Version 2.0]Add documents from code

Feb 6, 2013 at 8:50 PM
Edited Feb 6, 2013 at 8:51 PM
Well here's the thing. I've been trying to learn how MVVM works with avalon and I fail (I'm new in WPF, MVVM and Avalon, so it's quite hard), didn't get Avalon to show my controls, neither binding the tittle.

So now that I have up with using Avalon+MVVM I want to do it from code but can't get how to add a single document without using 'DocumentSource'.

Does anyone know how to do this? (Not from XAML)
Feb 7, 2013 at 5:21 PM
Edited Feb 7, 2013 at 8:18 PM
I just implemented AD MVVM style in my Open source project, please check



Relevant code from XAML is
DocumentsSource="{ Binding Documents }"
Base class for ViewModel for each Dockable panel

And then its very easy to add a doc, just do
Feb 8, 2013 at 7:08 PM
Edited Feb 8, 2013 at 7:09 PM
Thanks AndersM but I've already know that. My problem is that I can't display the document name on the Tab, neither add controls inside the document i've just add (Like Scintilla control I'm using on old versions).

I'll check that source that u've posted and then edit this msg. thx
Feb 10, 2013 at 10:50 AM
I'm just doing
                <Style TargetType="{x:Type avalondock:LayoutItem}">
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                    <Setter Property="IconSource" Value="{Binding Model.Icon}"/>
                    <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
See above source for complete XAML for my AvalonDock implementation
Feb 10, 2013 at 8:56 PM
I've send you a PM/mail could you check it please?
Feb 17, 2013 at 12:12 PM
Edited Feb 17, 2013 at 12:20 PM
Sorry missed that, checking it now


I'm using Caliburn Micro to bind the View
                        <ContentControl cal:View.Model="{Binding . }" IsTabStop="False" />
<ContentControl cal:View.Model="{Binding . }" IsTabStop="False" />

cal:View.Model is the magic, it will Look at the type of the view Model and then find the correct view depending on model

For example, DocumentViewModel.cs -> DocumentView.xaml

To communicate between models I use the EventAggregator pattern

Good luck!
Mar 6, 2013 at 11:07 PM
I can't get it. I've been breaking my head with the wall.

Let's make it someway simpler so I may can understand how this work.

I got a ViewModel something like:
Public Class DocumentViewModel
    Inherits BaseViewModel
    Implements IDisposable

    Private _name As String, _saved as Boolean

    Public Property Name As String
            Return If(Not _saved, String.Format("{0}*", _name), _name)
        End Get
        Set(value As String)
            If Not _name = value Then
                _name = value
            End If
        End Set
    End Property

    Public Property Saved As Boolean
            Return _saved
        End Get
        Set(value As Boolean)
            _saved = value
        End Set
    End Property

End Class
Now I've in a module (for it to be accessed from the hole project without any problems)
Public Documents As New ObservableCollection(Of DocumentViewModel) 'This collection is for DocumentSource
Now I've a View with 1 textbox and one button. When the button is pressed, the title of the document panel change to whatever is the text of the textbox. How to update the new document panel title on the Documents Collection? I mean how I'm supposed to find the right one? Or I'm just doing a mess and I should do this in an other way?
Mar 7, 2013 at 7:48 AM
Edited Mar 7, 2013 at 7:49 AM
If the Name property of the viewmodel is properly bound to the Title property of the LayoutItem (see Anders' post above), you don't have to do anything or need to "find the right one", the title should change in the moment you click the button automatically. I'm afraid nobody is able to help you unless you show us the relevant XAML code.