I am currently trying to create a UI using Avalon Dock from Xceed WPF Toolkit 3. I created a much simpler version of this example. Basically, my view model looks like this:
namespace NonWorkingAvalonDock {
public sealed class MainViewModel {
public MainViewModel() {
Pages = new SimplePageViewModel[] {
new SimplePageViewModel("Foo"),
new SimplePageViewModel("Bar")
};
}
public SimplePageViewModel[] Pages { get; }
}
public sealed class SimplePageViewModel {
public SimplePageViewModel(string title) {
Title = title;
}
public string Title { get; }
}
}
And my XAML looks like this:
<Window x:Class="NonWorkingAvalonDock.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NonWorkingAvalonDock"
xmlns:dock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:dockctrl="clr-namespace:Xceed.Wpf.AvalonDock.Controls;assembly=Xceed.Wpf.AvalonDock"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:MainViewModel x:Key="ViewModel" />
</Window.Resources>
<dock:DockingManager DataContext="{StaticResource ViewModel}" AnchorablesSource="{Binding Pages}" >
<dock:DockingManager.LayoutItemContainerStyle>
<!-- you can add additional bindings from the layoutitem to the DockWindowViewModel -->
<Style TargetType="{x:Type dockctrl:LayoutItem}" >
<Setter Property="Title" Value="{Binding Model.Title}" />
</Style>
</dock:DockingManager.LayoutItemContainerStyle>
</dock:DockingManager>
</Window>
When I look at the result in the Designer, It looks alright:
But when I run my application, the headers and titles are missing:
What is going wrong here?
Followup
I investigated the example and my code a bit more, and in the example, the author sets the data context in code behind. When I do this, it works for me, too.
Moreover, I did the following experiment: I made the Pages property privately writable, initialized it with null
and used a Timer
which sets the view models after one second. When I do this, I get the titles, too.
Is this a bug or do I have to do some additional stuff to make the binding appear without codebehind?