I am trying to add tabs dynamically using AvalonDock with WPF, but I am not able to do it.
Do you have a clue whar is wrong?
The code for adding tabs dynamicaly
public DockView()
{
MyDocuments = new ObservableCollection<DocumentContent>();
InitializeComponent();
}
public void CreateView()
{
string baseDocTitle = "MyDocument";
int i = 1;
string title = baseDocTitle + i.ToString();
while (dockManager.Documents.Any(d => d.Title == title))
{
i++;
title = baseDocTitle + i.ToString();
}
MyDocuments.Add(new DocumentContent() { Title = title });
}
public ObservableCollection<DocumentContent> MyDocuments { get; private set; }
XAML Code
<Menu>
<MenuItem Header="Documents">
<MenuItem Click="MenuItem_Click" Header="Create New" />
</MenuItem>
</Menu>
<ad:DockingManager x:Name="dockManager" Grid.Row="2"
DocumentsSource="{Binding MyDocuments}">
<ad:ResizingPanel>
<ad:DocumentPane />
</ad:ResizingPanel>
</ad:DockingManager>
You are trying to use features (binding) that aren’t available in release 1.3 of AvalonDock.
The good news is – the original author is re-writing the library to be MVVM-friendly 🙂
Check out the link:
http://avalondock.codeplex.com/wikipage?title=Version2Concept&referringTitle=Home
The new version just went into Alpha so will be around 2 months away from being production-ready but you can play with it for now.
If you can’t wait and need a MVVM friendly version of 1.3 in the meantime, I suggest the solution presented in this article:
http://msdn.microsoft.com/en-us/magazine/ff798279.aspx
Steve