[英]Avalon Dock and Caliburn Micro - no title on document pane (tab header)
我熟悉Caliburn Micro及其使用的范例,但我現在正在嘗試集成AvalonDock。
作為一個POC,我有一個非常簡單的應用程序,其中一個shell視圖模型包含一個按鈕,用於激活我的StructureViewModels - 一個包含名稱和標題的簡單類。 結構視圖是一個用戶控件,它只是將名稱顯示為文本。
ViewModel和Views正在使用Caliburn很好地連接,它們正在Docking Manager中顯示。 我可以拖動和分離,枚舉窗格等 - 所有Avalon功能似乎都有效。 我遇到的問題是它們在Avalon標題(標簽)中沒有標題顯示。
ShellViewModel:
using AvalonDemo.Properties;
using Caliburn.Micro;
namespace AvalonDemo.ViewModels
{
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
{
private int _structureCount;
public ShellViewModel()
{
WindowTitle = Resources.MainWindowTitle;
_structureCount = 1;
}
public string WindowTitle { get; set; }
public void OpenStructure()
{
ActivateItem(new StructureViewModel
{
Name = "Structure" + _structureCount++,
Title = "Structure" + _structureCount
});
}
}
}
編輯解決方案:
ShellView:
<Window x:Class="AvalonDemo.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonDock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:cal="http://www.caliburnproject.org"
xmlns:common="clr-namespace:AvalonDemo.Common"
Title="{Binding WindowTitle}"
Height="850" Width="1200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button x:Name="OpenStructure" Grid.Row="0" Width="50">Open</Button>
<avalonDock:DockingManager
Grid.Row="1" x:Name="DockingManager"
DocumentsSource="{Binding Items}">
<avalonDock:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type avalonDock:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}" />
</Style>
</avalonDock:DockingManager.LayoutItemContainerStyle>
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<common:AutobinderTemplateSelector>
<common:AutobinderTemplateSelector.Template>
<DataTemplate>
<ContentControl cal:View.Model="{Binding . }" IsTabStop="False" />
</DataTemplate>
</common:AutobinderTemplateSelector.Template>
</common:AutobinderTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>
<avalonDock:LayoutRoot>
<avalonDock:LayoutPanel Orientation="Horizontal">
<avalonDock:LayoutDocumentPaneGroup>
<avalonDock:LayoutDocumentPane />
</avalonDock:LayoutDocumentPaneGroup>
</avalonDock:LayoutPanel>
</avalonDock:LayoutRoot>
</avalonDock:DockingManager>
</Grid>
</Window>
StructureViewModel:
using Caliburn.Micro;
namespace AvalonDemo.ViewModels
{
public class StructureViewModel : Screen
{
public string Name { get; set; }
public string Title { get; set; }
}
}
StructureView:
<UserControl x:Class="AvalonDemo.Views.StructureView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<TextBlock Text="{Binding Path=Name}" />
</Grid>
</UserControl>
最后,我使用Autobinder選擇DataTemplates:
using System.Windows;
using System.Windows.Controls;
namespace AvalonDemo.Common
{
public class AutobinderTemplateSelector : DataTemplateSelector
{
public DataTemplate Template { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
return Template;
}
}
}
我試圖將代碼限制到最小只是為了讓POC正常工作,但是沒有看到很多(任何?)使用Caliburn處理活動虛擬機和Avalon Dock 2.0的工作示例。
提前致謝。
哦,我昨晚花了很多時間嘗試一下,一發布問題,我就找到了答案(StackOverflow-rubber duck?)
希望這有助於其他人,我只需要一個LayoutItemContainerStyle添加到shell視圖,告訴Avalon從哪里獲取Title:
<avalonDock:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type avalonDock:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}" />
</Style>
</avalonDock:DockingManager.LayoutItemContainerStyle>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.