【问题标题】:Avalon Dock and Caliburn Micro - no title on document pane (tab header)Avalon Dock 和 Caliburn Micro - 文档窗格上没有标题(选项卡标题)
【发布时间】:2014-07-17 08:46:48
【问题描述】:

我熟悉 Caliburn Micro 及其使用的范例,但现在正在尝试集成 AvalonDock。

作为 POC,我有一个非常简单的应用程序,它带有一个外壳视图模型,其中包含一个用于激活我的 StructureViewModels 的按钮 - 一个包含名称和标题的简单类。该结构的视图是一个用户控件,仅将名称显示为文本。

ViewModels 和 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>

结构视图模型:

using Caliburn.Micro;

namespace AvalonDemo.ViewModels
{
    public class StructureViewModel : Screen
    {
        public string Name { get; set; }
        public string Title { get; set; }
    }
}

结构视图:

<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 处理活动 VM 和 Avalon Dock 2.0 的工作示例。

提前致谢。

【问题讨论】:

  • 已编辑解决方案,希望对某人有所帮助。

标签: c# wpf mvvm caliburn.micro avalondock


【解决方案1】:

哦,天哪,昨晚我花了很长时间尝试,一发布问题,我就找到了答案(StackOverflow-橡皮鸭?)

希望这对其他人有所帮助,我只需要在 shell 视图中添加一个 LayoutItemContainerStyle 来告诉 Avalon 从何处获取标题:

<avalonDock:DockingManager.LayoutItemContainerStyle>
     <Style TargetType="{x:Type avalonDock:LayoutItem}">
          <Setter Property="Title" Value="{Binding Model.Title}" />
     </Style>
</avalonDock:DockingManager.LayoutItemContainerStyle>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    相关资源
    最近更新 更多