I'm using AvalonDock control in my project. When i move my document anywhere and detach from control, document content disapear. And if i redock document to a control, document content come out. I'm sure i'm missing something so simple but i don't understand the problem. Here is the code snippet from the MainView;
<xcad:DockingManager AllowMixedOrientation="True" DocumentsSource="{Binding DocumentViewModels}">
<xcad:DockingManager.Resources>
<DataTemplate DataType="{x:Type viewModels:WatchListViewModel}">
<local:WatchListView DataContext="{Binding}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:ScanListViewModel}">
<local:ScanListView DataContext="{Binding}"/>
</DataTemplate>
<DataTemplate DataType="{x:Type viewModels:SignalListViewModel}">
<local:SignalListView DataContext="{Binding}"/>
</DataTemplate>
</xcad:DockingManager.Resources>
<xcad:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type xcad:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Document.Title}"/>
</Style>
</xcad:DockingManager.LayoutItemContainerStyle>
</xcad:DockingManager>
For clarify the problem want to share three screenshots. First screenshot is showing document before move anywhere. Second screenshot is showing document after move anywhere (floating). And third screenshot is showing re-dock to same place. Actually first and third image same but i want to show clearly that actually content still there.
You need to add a DataTemplateSelector
to your code, in order to teach AvalonDock which DataTemplate used for your own View/ViewModel.
In order to do so, you need to define a new class like the following:
class PanesTemplateSelector : System.Windows.Controls.DataTemplateSelector
{
public DataTemplate WatchListViewTemplate { get; set; }
public DataTemplate ScanListViewTemplate { get; set; }
public DataTemplate SignalListViewTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is WatchListViewModel)
return WatchListViewTemplate;
if (item is ScanListViewModel)
return ScanListViewTemplate;
if (item is SignalListViewModel)
return SignalListViewTemplate;
return base.SelectTemplate(item, container);
}
}
Then you need to add this class yo your XAML as follow:
<xcad:DockingManager.LayoutItemTemplateSelector>
<s:PanesTemplateSelector>
<s:PanesTemplateSelector.WatchListViewTemplate>
<DataTemplate>
<p:WatchListView />
</DataTemplate>
</s:PanesTemplateSelector.WatchListViewTemplate>
<s:PanesTemplateSelector.ScanListViewTemplate>
<DataTemplate>
<p:ScanListView />
</DataTemplate>
</s:PanesTemplateSelector.ScanListViewTemplate>
<s:PanesTemplateSelector.SignalListViewTemplate>
<DataTemplate>
<p:SignalListView />
</DataTemplate>
</s:PanesTemplateSelector.SignalListViewTemplate>
</s:PanesTemplateSelector>
</xcad:DockingManager.LayoutItemTemplateSelector>
Where s
links to the namespace where you define the PanesTemplateSelector
and p
links to the namespace where you define your own Views